Connecting to Oracle for the first time on a new machine, container or app server almost always produces one of these:
ORA-12154: TNS:could not resolve the connect identifier specified
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
ORA-12541: TNS:no listener
ORA-12170: TNS:Connect timeout occurred
They look alike but mean very different things. Read the number, and you know which layer to check.
How an Oracle connection is resolved
- The client turns your connect identifier (
PRODDB, orhost:port/service) into an address and a service name, usingtnsnames.ora, EZConnect, LDAP and so on. - It opens a TCP connection to the listener on that host and port (default 1521).
- The listener hands the connection to the database service you asked for, if a database instance has registered that service with it.
Each error corresponds to one of those steps.
ORA-12154: the client can't resolve the name (step 1)
The alias you used (sqlplus scott@PRODDB) wasn't found. The server was never contacted. Check:
- Which
tnsnames.orathe client reads. It's found throughTNS_ADMIN, or$ORACLE_HOME/network/admin. Machines often have several Oracle homes or Instant Client installs. SetTNS_ADMINexplicitly, and check that the alias exists in that file. - Typos and syntax in
tnsnames.ora: unbalanced parentheses break every entry after the error. sqlnet.oranaming methods:NAMES.DIRECTORY_PATH = (TNSNAMES, EZCONNECT)must include the method you're using.- Drivers that ignore
tnsnames.ora: JDBC thin, and python-oracledb in thin mode, needTNS_ADMINor aconfig_dirparameter to read it.
The quickest workaround is to skip tnsnames.ora entirely with EZConnect:
sqlplus scott@//db01.example.com:1521/orclpdb1
jdbc:oracle:thin:@//db01.example.com:1521/orclpdb1
