Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
393 views
in Technique[技术] by (71.8m points)

oracle - Determining location of relevant tnsnames.ora file

I installed both the 32 and 64-bit Oracle 11g drivers. I search my PC looking for files with the name "tnsnames.ora" and found 3 in the following locations:

1. C:Oracleproduct11203_32bitCLIENT_1NETWORKADMIN
2. C:Oracleproduct11203_64bitCLIENT_1NETWORKADMIN
3. C:WindowsTNS

The existence of the 3rd location of the tnsnames.ora file surprises me.

I have the following Oracle clients installed on my PC:

"C:Program Files (x86)Quest SoftwareToad for Oracle 11.6Toad.exe"
"C:Program FilesDevartdbForge Studio Express for Oracledbforgeoracle.exe"

Based on the location of each program (Program Files (x86) vs. c:Program Files), This suggests to me that the Toad, a 32 bit program, should use the 32 bit driver and dbForge should use the 64 bit driver.

dbForge seems to use either the tnsnames.ora file in either location #2 or #3. I know this by systematically renaming all but one of the tns files and then checking to see if the connection names read from the file are available when trying to create a new connection from with the app.

However, TOAD seems to only recognize the tnsnames.ora file in location #3 and it did not recognize the tnsnames.ora file in location 2 at all! (Being that it was a 32 bit program, I did not expect it to recognize the tns file in location 2 and that was the case). TO summarize the TOAD test for the sake of hopeful clarity, TOAD only recognized the tns file in location 3.

Other colleagues do not have a tns file in location 3 on their machines. I'm not sure why I do. When I run Toad, it shows the following 2 Home, with the 32 bit Home as being the active one.

OraClient11g_home1 (11.2.0.3)
    ORACLE_HOME:C:appC39293product11.2.0client_1
    ORACLE_HOME_NAME:OraClient11g_home1
    ORACLE_HOME_KEY:HKEY_LOCAL_MACHINESOFTWAREORACLEKEY_OraClient11g_home1
    ORACLE_SID:
    NLS_LANG:AMERICAN_AMERICA.WE8MSWIN1252
    SQLPATH:
    LOCAL:
    Client DLL:C:appC39293product11.2.0client_1oci.dll
    TNSNames.ora:
    SQLNet.ora:
    LDAP.ora:
    Login.sql:
    GLogin.sql:
    In system PATH:No
    Home is valid:No
OraClient11g_home1_32bit (11.2.0.3)
    ORACLE_HOME:c:oracleproduct11203_32bitCLIENT_1
    ORACLE_HOME_NAME:OraClient11g_home1_32bit
    ORACLE_HOME_KEY:HKEY_LOCAL_MACHINESOFTWAREORACLEKEY_OraClient11g_home1_32bit
    ORACLE_SID:
    NLS_LANG:AMERICAN_AMERICA.WE8MSWIN1252
    SQLPATH:c:oracleproduct11203_32bitCLIENT_1dbs
    LOCAL:
    Client DLL:c:oracleproduct11203_32bitCLIENT_1inoci.dll
    TNSNames.ora:
    SQLNet.ora:
    LDAP.ora:
    Login.sql:
    GLogin.sql:c:oracleproduct11203_32bitCLIENT_1sqlplusadminglogin.sql
    In system PATH:Yes

Q1: Is OraClient11g_home1 my 64 bit home or do I have two Oracle clients installed?

Q2: Why doesn't 32 bit TOAD use the tns in location #1 instead of only using the one in location #3?

Q3: If I leave on the tns file in location 3, both dbForge and TOAD work but I'd like to know why so I can accurately understand how to move tns info from one machine to another.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

According Oracle these locations are searched for tnsnames.ora, resp. sqlnet.ora and ldap.ora:

  1. Oracle Net files in present working directory (PWD/CWD)
  2. TNS_ADMIN defined sessionally or by user-defined script
  3. TNS_ADMIN defined as a global environment variable
  4. TNS_ADMIN defined in the registry
  5. Oracle Net files in %ORACLE_HOME/network|net80admin (Oracle default location)

However, I am not sure whether each application/driver follows this list. I got this list from Oracle Document 111942.1 referring to Oracle 9i, so it might be outdated.

In Database Net Services Administrator's Guide the order is

  1. TNS_ADMIN defined by environment variable
  2. TNS_ADMIN defined in the registry (if TNS_ADMIN environment variable is not present)
  3. %ORACLE_HOME%/network/admin directory (if TNS_ADMIN environment variable is not present)

I would recommend to define an environment variable for TNS_ADMIN and use only one tnsnames.ora file. In order to be on the safe side, check also your registry values.

If your files are not located in %ORACLE_HOME% etworkadmin, I recommend to create a symbolic link for it - just to be on the very safe side, e.g. mklink /d %ORACLE_HOME% etworkadmin c:Oraclecommonsettingsadmin

Another note, you don't have to "play" with your tnsnames.ora file. With Process Monitor from Microsoft Sysinternals you can monitor each file access, i.e. the filter would be Path contains tnsnames

Update

When I run a test on my machine I get following order:

  1. Environment variable TNS_ADMIN
  2. Registry Key HKEY_CURRENT_USERSOFTWAREORACLEKEY_{Oracle_Home_Name}TNS_ADMIN
  3. Registry Key HKEY_LOCAL_MACHINESOFTWAREORACLEKEY_{Oracle_Home_Name}TNS_ADMIN, resp. HKEY_LOCAL_MACHINESOFTWAREWow6432NodeORACLEKEY_{Oracle_Home_Name}TNS_ADMIN

    -> Only if TNS_ADMIN Environment variable is not set.

  4. %ORACLE_HOME% etworkadmin
  5. Current directory (which can be different to directory where your application is located)
  6. Folder where your application is located

Update 2

Obviously there is no fix search, it varies for different providers/drivers. Maybe it also depends on the Oracle version.

For example, the Oracle HTTP Server reads TNS_ADMIN setting from opmn.xml config file.

Another example, for ODP.NET Managed Driver (Oracle.ManagedDataAccess) beta version, I found this order at Oracle Managed and TNS Names :

  1. data source alias in the 'dataSources' section under <oracle.manageddataaccess.client> section in the .NET config file (i.e. machine.config, web.config, user.config).
  2. data source alias in the tnsnames.ora file at the location specified by TNS_ADMIN in the .NET config file.
  3. data source alias in the tnsnames.ora file present in the same directory as the .exe.
  4. data source alias in the tnsnames.ora file present at %TNS_ADMIN%
    (where %TNS_ADMIN% is an environment variable setting).
  5. data source alias in the tnsnames.ora file present at %ORACLE_HOME% etworkadmin
    (where %ORACLE_HOME% is an environment variable setting).

In official documentation (12c Release 4 (12.1.0.2.4)) it says:

  1. data source alias in the dataSources section under <oracle.manageddataaccess.client> section in the .NET config file (i.e. machine.config, web.config, user.config).
  2. data source alias in the tnsnames.ora file at the location specified by TNS_ADMIN in the .NET config file. Locations can consist of either absolute or relative directory paths.
  3. data source alias in the tnsnames.ora file present in the same directory as the .exe.

However, based on some tests I made with ODP.NET Managed Driver (4.121.2.0) it takes %ORACLE_HOME% etworkadmin and TNS_ADMIN Environment variable into account. Locks like the documentation is not 100% correct.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...