Oracle - What TNS Names file am I using?

前端 未结 11 619
长发绾君心
长发绾君心 2020-12-07 13:50

Sometimes I get Oracle connection problems because I can\'t figure out which tnsnames.ora file my database client is using.

What\'s the best way to figure this out?

相关标签:
11条回答
  • 2020-12-07 14:18

    For linux:

    $ strace sqlplus -L scott/tiger@orcl 2>&1| grep -i 'open.*tnsnames.ora'
    

    shows something like this:

    open("/opt/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora",O_RDONLY)=7
    

    Changing to

    $ strace sqlplus -L scott/tiger@orcl 2>&1| grep -i 'tnsnames.ora'
    

    will show all the file paths that are failing.

    0 讨论(0)
  • 2020-12-07 14:24

    On my development machine I have three different versions of Oracle client software. I manage the tnsnames.ora file in one of them. In the other two, I have entered in the tnsnames.ora file:

    ifile=path_to_tnsnames.ora_file/tnsnames.ora
    

    This way, if for some reason the wrong tnsnames.ora file is used by a client, it will always end up at the up-to-date version.

    0 讨论(0)
  • 2020-12-07 14:24

    strace sqlplus -L scott/tiger@orcl helps to find .tnsnames.ora file on /home/oracle to find the file it takes instead of $ORACLE_HOME/network/admin/tnsnames.ora file. Thanks for the posting.

    0 讨论(0)
  • 2020-12-07 14:28

    Oracle provides a utility called tnsping:

    R:\>tnsping someconnection
    
    TNS Ping Utility for 32-bit Windows: Version 9.0.1.3.1 - Production on 27-AUG-20
    08 10:38:07
    
    Copyright (c) 1997 Oracle Corporation.  All rights reserved.
    
    Used parameter files:
    C:\Oracle92\network\ADMIN\sqlnet.ora
    C:\Oracle92\network\ADMIN\tnsnames.ora
    
    TNS-03505: Failed to resolve name
    
    R:\>
    
    
    R:\>tnsping entpr01
    
    TNS Ping Utility for 32-bit Windows: Version 9.0.1.3.1 - Production on 27-AUG-20
    08 10:39:22
    
    Copyright (c) 1997 Oracle Corporation.  All rights reserved.
    
    Used parameter files:
    C:\Oracle92\network\ADMIN\sqlnet.ora
    C:\Oracle92\network\ADMIN\tnsnames.ora
    
    Used TNSNAMES adapter to resolve the alias
    Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (COMMUNITY = **)
     (PROTOCOL = TCP) (Host = ****) (Port = 1521))) (CONNECT_DATA = (SID = ENTPR0
    1)))
    OK (40 msec)
    
    R:\>
    

    This should show what file you're using. The utility sits in the Oracle bin directory.

    0 讨论(0)
  • 2020-12-07 14:29

    By default, tnsnames.ora is located in the $ORACLE_HOME/network/admin directory on UNIX operating systems and in the ORACLE_HOME\network\admin directory on Windows operating systems. tnsnames.ora can also be stored the following locations:

    The directory specified by the TNS_ADMIN environment variable (or registry value)

    On UNIX operating systems, the global configuration directory. For example, on the Solaris Operating System, this directory is /var/opt/oracle

    If you have multiple ORACLE_HOMES, be aware of which one you are using, as the location of the tnsnames.ora file can vary from one ORACLE_HOME to the next.

    For the person who mentioned the TWO_TASK environment variable, that is used to set a default database service name to connect to (which could be a database on another server). The service name you set TWO_TASK to is then looked up in the tnsnames.ora file when you connect.

    0 讨论(0)
  • 2020-12-07 14:30

    The easiest way is probably to check the PATH environment variable of the process that is connecting to the database. Most likely the tnsnames.ora file is in first Oracle bin directory in path..\network\admin. TNS_ADMIN environment variable or value in registry (for the current Oracle home) may override this.

    Using filemon like suggested by others will also do the trick.

    0 讨论(0)
提交回复
热议问题