TNS_ADMIN Environment Variable in Oracle

Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
  • User AvatarANKUSH THAVALI
  • 12 Sep, 2023
  • 0 Comments
  • 1 Min Read

TNS_ADMIN Environment Variable in Oracle

TNS_ADMIN Environment Variable in Oracle

When multiple installation of Oracle homes and client are done, Use of TNS_ADMIN is defined for tnsnames.ora location. TNS_ADMIN environment variable  specifies the directory location for the tnsnames.ora file.

If tnsnames.ora is not properly set then it will give the following errors:
ORA-12154: TNS: could not resolve service name or SQL*NET Unable to resolve service name.

Set in Environment Variable of Windows:

  1. Search the Environment Variables and open window.
  2. In the System variables section click the New button for create new entry.
  3. Enter a variable name as TNS_ADMIN then enter a variable value of the path to the TNSNAMES.ORA file that will be used as the default.
    For example:
    Name: TNS_ADMIN
    Value: C:\data\app\oracle\product\dbhomeXE\network\admin



For set at command prompt:
SET TNS_ADMIN=C:\data\app\oracle\product\dbhomeXE\network\admin

Set TNS_ADMIN Parameter in Linux

First we need to create a directory which will act as a central location for listener.ora & tnsnames.ora. Please Note : keep it outside any specific ORACLE_HOME
mkdir -p $ORACLE_BASE/network
It’s a good idea to set this parameter inside the .bash_profile and add below line
export TNS_ADMIN=$ORACLE_BASE/network
Great, no matter which ORACLE_HOME you are connected to, the lsnrctl utility will ready listener.ora file from TNS_ADMIN location. Also, any tns connections will be using tnsnames.ora file placed inside TNS_ADMIN location!  

Hope it helps!