ChatGPT解决这个技术问题 Extra ChatGPT

Oracle TNS names not showing when adding new connection to SQL Developer

I'm trying to connect to an oracle database with SQL Developer.

I've installed the .Net oracle drivers and placed the tnsnames.ora file at
C:\Oracle\product\11.1.0\client_1\Network\Admin

I'm using the following format in tnsnames.ora:

dev =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.XXX.XXX)(PORT = XXXX))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = idpdev2)
    )
  )

In SQL Developer, when I try to create a new connection, no TNS-names show up as options.

Is there something I'm missing?


K
Kris Rice

SQL Developer will look in the following location in this order for a tnsnames.ora file

$HOME/.tnsnames.ora $TNS_ADMIN/tnsnames.ora TNS_ADMIN lookup key in the registry /etc/tnsnames.ora ( non-windows ) $ORACLE_HOME/network/admin/tnsnames.ora LocalMachine\SOFTWARE\ORACLE\ORACLE_HOME_KEY LocalMachine\SOFTWARE\ORACLE\ORACLE_HOME

To see which one SQL Developer is using, issue the command show tns in the worksheet

If your tnsnames.ora file is not getting recognized, use the following procedure:

Define an environmental variable called TNS_ADMIN to point to the folder that contains your tnsnames.ora file. In Windows, this is done by navigating to Control Panel > System > Advanced system settings > Environment Variables... In Linux, define the TNS_ADMIN variable in the .profile file in your home directory. Confirm the os is recognizing this environmental variable From the Windows command line: echo %TNS_ADMIN% From linux: echo $TNS_ADMIN Restart SQL Developer Now in SQL Developer right click on Connections and select New Connection.... Select TNS as connection type in the drop down box. Your entries from tnsnames.ora should now display here.


For me: $HOME/.tnsnames.ora didn't work ... I used $HOME/tnsnames.ora instead. Also Note: You will need to go to Tools -> Preferences, search for "tns" and point the directory to $HOME
Despite this being in release notes for SQL developer 1.5 version, I found that on Ubuntu 12.04 LTS only #5 worked. Try these steps to check if that's your case: forums.oracle.com/message/2769285#2769285. Noteworthy: author had the problem on Win Vista.
Worked for me in Windows. Logging things forever FTW!
Setting TNS_ADMIN did not work for me. Instead, I searched the computer for all TNSNAMES Files and updated the contents of all of them. No idea why Windows 7 Sql Developer persisted on using some other TNSNAMES File in some old folder.
Note: $TNS_ADMIN is the DIRECTORY not the actual .ora file
P
Paul Mattey

Open SQL Developer. Go to Tools -> Preferences -> Databases -> Advanced Then explicitly set the Tnsnames Directory

My TNSNAMES was set up correctly and I could connect to Toad, SQL*Plus etc. but I needed to do this to get SQL Developer to work. Perhaps it was a Win 7 issue as it was a pain to install too.


Accepted answer did not work for me but this did (Windows Server 2008R2)
Had the same issue, but SQL Developer also looked in %userprofile%\tnsnames.ora before %TNS_ADMIN%\tnsnames.ora, and that's where I had the extra tnsnames.ora file.
P
Peter Lang

You can always find out the location of the tnsnames.ora file being used by running TNSPING to check connectivity (9i or later):

C:\>tnsping dev

TNS Ping Utility for 32-bit Windows: Version 10.2.0.1.0 - Production on 08-JAN-2009 12:48:38

Copyright (c) 1997, 2005, Oracle.  All rights reserved.

Used parameter files:
C:\oracle\product\10.2.0\client_1\NETWORK\ADMIN\sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = XXX)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = DEV)))
OK (30 msec)

C:\>

Sometimes, the problem is with the entry you made in tnsnames.ora, not that the system can't find it. That said, I agree that having a tns_admin environment variable set is a Good Thing, since it avoids the inevitable issues that arise with determining exactly which tnsnames file is being used in systems with multiple oracle homes.


how can I install tnsping tool ??
In the client install there is a checkbox for Database Tools or some such.
C
Chandra Sekhar

https://i.stack.imgur.com/28b8A.png

https://i.stack.imgur.com/IgzUW.png

You have Done!

Now you can connect via the TNSnames options.


Can't find "Databse:Advanced" ==>my version is 1.5.5
For versions lower than 2.1 or if you haven't specified a Tnsnames directory on 2.1 or higher please fallow as specified in @JasonAnderson answer.
I do not have Tnsnames Directory option in Tools->Preferences->Databaes->Advanced Parameters menu. I'm using SqlDeveloper v1.1.3
A
Allan Stewart

The steps mentioned by Jason are very good and should work. There is a little twist with SQL Developer, though. It caches the connection specifications (host, service name, port) the first time it reads the tnsnames.ora file. Then, it does not invalidate the specs when the original entry is removed from the tnsname.ora file. The cache persists even after SQL Developer has been terminated and restarted. This is not such an illogical way of handling the situation. Even if a tnsnames.ora file is temporarily unavailable, SQL Developer can still make the connection as long as the original specifications are still true. The problem comes with their next little twist. SQL Developer treats service names in the tnsnames.ora file as case-sensitive values when resolving the connection. So if you used to have an entry name ABCD.world in the file and you replaced it with an new entry named abcd.world, SQL Developer would NOT update its connection specs for ABCD.world - it will treat abcd.world as a different connection altogether. Why am I not surprised that an Oracle product would treat as case-sensitive the contents of an oracle-developed file format that is expressly case-insensitive?


@allen: do you know how to force it to clear this list? If so, please respond to stackoverflow.com/q/6412559/168646
B
B Chowdhary

In Sql Developer, navidate to Tools->preferences->Datababae->advanced->Set Tnsname directory to the directory containing tnsnames.ora


M
Michael

None of the above changes made any difference in my case. I could run TNS_PING in the command window but SQL Developer couldn't figure out where tnsnames.ora was.

The issue in my case (Windows 7 - 64 bit - Enterprise ) was that the Oracle installer pointed the Start menu shortcut to the wrong version of SQL Developer. There appear to be three SQL Developer instances that accompany the installer. One is in %ORACLE_HOME%\client_1\sqldeveloper\ and two are in %ORACLE_HOME%\client_1\sqldeveloper\bin\ .

The installer installed a start menu shortcut that pointed at a version in the bin directory that simply did not function. It would ask for a password every time I started SQL Developer, not remember choices I had made and displayed a blank list when I chose TNS as the connection mechanism. It also does not have the TNS Directory field in the Database advanced settings referenced in other posts.

I tossed the old Start shortcut and installed a shortcut to %ORACLE_HOME%\client_1\sqldeveloper\sqldeveloper.exe . That change fixed the problem in my case.


S
SiB

At windows I must add permision "READ & execure" for:

folder c:\oracle\TNS_ADMIN

file c:\oracle\TNS_ADMIN\tnsnames.ora

of course the Windows see:

C:\>set TNS
TNS_ADMIN=c:\oracle\TNS_ADMIN

and now SQL Developer see TNS on list.


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now