About the ORA-12154 Error

By:


TNS:could not resolve service name

This error, seen as ORA-12154, means SQL*Net could not find the database alias specified for a database connection in the TNSNAMES.ORA file or other naming adapter. The database alias is specified after the “@” character in a database connection string. For example, if the connect string “SYSTEM/MANAGER@PROD” is used, “PROD” is the database alias.

How to troubleshoot ORA-12154

The following is a list of steps to follow when troubleshooting an ORA-12154 error.

  1. Find the Oracle SQL*Net configuration files– there are two main files Oracle uses on the client when connecting to a database, TNSNAMES.ORA and SQLNET.ORA. Oracle will typically scan for these files using the following sequence:
    1. Current Directory – the directory the application was started from. SQL*Plus typically resides in ORACLE_HOME\bin, but if the current directory was C:\TEMP when it started, Oracle will look here first.
    2. TNS_ADMIN – the directory specified by the TNS_ADMIN environment variable or registry entry
    3. /var/opt/oracle (UNIX only)
    4. ORACLE_HOME\network\admin

    Sometimes you can also use the TNSPING utility to determine where the files are located. As part of the output, this utility typically displays the parameters files used.

  2. Determine the converted database alias name that Oracle will use– inside the SQLNET.ORA file determine if a parameter NAMES.DEFAULT_DOMAIN is specified. For example, you may see a line that reads:
    NAMES.DEFAULT_DOMAIN = mycompany.com
    

    In that case, Oracle will append this name to the database alias name to connect to the database. For example, if you use a database alias of PROD, the converted name Oracle will use is “PROD.MYCOMPANY.COM” (case insensitive). If this parameter is not found the converted alias would be “PROD”

  3. Find the converted alias name in the TNSNAMES.ORA file– inside the TNSNAMES.ORA file, search for the converted alias name to find an exact match. A typical entry would look similar to the following (ignoring white spaces):
    PROD.MYCOMPANY.COM = 
         (DESCRIPTION = 
           (ADDRESS_LIST = 
               (ADDRESS = 
                 (PROTOCOL = TCP) 
                 (Host = PRODMACHINE.MYCOMPANY.COM) 
                 (Port = 1521))) 
           (CONNECT_DATA = (SERVICE_NAME = ORCL)))
    

    If an exact match is not found, you will receive a TNS-12154 error. If you find an entry that looks similar, i.e. the alias in the TNSNAMES.ORA read “PROD” without the domain name appended to it, then either; 1) add the domain to the end of TNSNAMES.ORA alias name; or 2) remove the NAMES.DEFAULT_DOMAIN parameter from the SQLNET.ORA file.

    If no similar matches are found, an entry similar to the one shown above will need to be added to the TNSNAMES.ORA file.

  1. Modify the AUTOMATIC_IPC parameter in SQLNET.ORA – if this parameter is currently set to ON, change it to OFF. If it is currently OFF, change it to ON. Try the connection again.
  2. Verify the TNSNAMES.ORA and SQLNET.ORA files are accessible – If the files exist and appear to be configured properly, verify the permissions are set properly. Try changing the permissions to full open, e.g. if this is UNIX then change the permissions to “rwxrwxrwx” (chmod 777 tnsnames.ora).
  3. Manually configure the environment – if all else fails, set the TNS_ADMIN environment variable to “C:\TEMP” and create a new TNSNAMES.ORA file in that directory. Add the proper entry to the TNSNAMES.ORA file and the connection should work.

Leave a Reply