Sql*Plus ERROR: ORA-12154: TNS:could not resolve the connect identifier specified

oracleoracle-11gsqlplus

I installed Sql*PLUS on a cloud Oracle Linux Environment in order to access an remote database. I used the installation instructions provided as an answer here: https://stackoverflow.com/questions/23488394/how-to-install-sql-plus-client-in-linux

My connection string is correct, but I get the error

ERROR: ORA-12154: TNS:could not resolve the connect identifier specified

I tried resolving this issue by attempting to looking at my tnsnames.ora, but it did not exist and the path connected to my $ORACLE_HOME did not have the subfolders "/network/admin/". In order to resolve this, I created both folders and created a tnsnames.ora file in the new admin/ containing my connection string. Unfortunately, I still get the same error.

The path to my new tnsnames.ora file being:
/usr/lib/oracle/11.2/client64/network/admin/tnsnames.ora

For reference my connection string is structured the following way:

(DESCRIPTION=
     (ADDRESS=(PROTOCOL=tcp)(HOST= asdasdasd.com)(PORT=1524))
    (CONNECT_DATA =
      (SID = AARCER1)
    )
  )

And my command I am putting into my terminal is:
sqlplus "userName/myPassword@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=asdasdasd.com)(PORT=1524))(CONNECT_DATA=(SID=AARCER1)))"

What should I do to resolve this error?

Best Answer

When you use sqlplus userName/myPassword@"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=asdasdasd.com)(PORT=1524))(CONNECT_DATA=(SID=AARCER1)))" then you don't need any tnsnames.ora file.

Your entry in tnsnames.ora file should be like this:

AARCER1 = (DESCRIPTION=
     (ADDRESS=(PROTOCOL=tcp)(HOST= asdasdasd.com)(PORT=1524))
    (CONNECT_DATA =
      (SID = AARCER1)
    )
  )

Then you can shorten your command to sqlplus userName/myPassword@AARCER1 - that is the purpose of tnsnames.ora.

In order to use tnsnames.ora you must also have file sqlnet.ora. There you need an entry like this:

NAMES.DIRECTORY_PATH = (TNSNAMES)

However, default value is NAMES.DIRECTORY_PATH=(tnsnames, ldap, ezconnect), so actually you can skip it.

Set environment variable TNS_ADMIN to location of these files, i.e.

export TNS_ADMIN=/usr/lib/oracle/11.2/client64/network/admin
Related Question