Sub topic 13
Troubleshooting Common Oracle Connection Errors
Assume that you know basic SQL, can use a terminal, and have an Oracle account and a reachable database. This chapter focuses on connection failures before SQL statements run.
Use a Layered Diagnosis
An Oracle connection must pass several layers:
- Your client must resolve the connect identifier.
- The client must reach the database host and port.
- The listener must recognize the requested service.
- The database must accept the username and password.
First check that the client is using the intended host, port, service name, and username. A typo can produce a valid-looking connection attempt to the wrong database.
ORA-12541: No Listener
ORA-12541: TNS:no listener means the client reached no Oracle listener at the requested network address. Common causes include:
- The listener is stopped.
- The host name is wrong.
- The port is wrong. The default listener port is often 1521, but it can differ.
- A firewall blocks the connection.
Check the Easy Connect details:
sql hr@//dbhost.example.com:1521/orclpdb1.example.comAsk the database administrator to confirm that the listener is running and listening on that port. On a host you administer, lsnrctl status reports listener status and registered services.
Do not treat this error as a password problem. Authentication has not started yet.
ORA-12514: Unknown Service
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor means the listener responded, but it does not know the requested service name.
Check the final part of the connection identifier:
//dbhost.example.com:1521/orclpdb1.example.comThe value after the final slash is a service name. It is not necessarily the database name, container name, or SID. Confirm the exact service name with the administrator or the database deployment details. In a multitenant database, connecting to the wrong pluggable-database service is a common cause.
ORA-12154: Cannot Resolve the Connect Identifier
ORA-12154: TNS:could not resolve the connect identifier specified usually occurs with a TNS alias such as ORCLPDB.
The client must find an entry like this in tnsnames.ora:
ORCLPDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = dbhost.example.com)(PORT = 1521))
(CONNECT_DATA = (SERVICE_NAME = orclpdb1.example.com))
)Check the alias spelling and the tnsnames.ora location. SQL Developer and SQLcl can use different Oracle configuration directories. If the alias works in one tool but not the other, compare each tool's network configuration.
As a diagnostic, replace the alias with Easy Connect syntax. If Easy Connect works, the network and service are probably correct, and the problem is alias configuration.
ORA-01017: Invalid Credentials
ORA-01017: invalid username/password; logon denied means the server rejected the credentials. Check:
- The username is spelled correctly.
- The password uses the correct capitalization.
- You are connecting to the intended service.
- The account is not locked or expired.
- The password was not altered by shell quoting or copied whitespace.
Avoid putting passwords directly in command history or scripts. Start SQLcl without a connection, then enter the password at the prompt:
sql /nolog
SQL> connect hr@//dbhost.example.com:1521/orclpdb1.example.com
Password? ********
Connected.Verify Before Investigating Further
Run this query after a successful login:
select sys_context('USERENV', 'SESSION_USER') as session_user,
sys_context('USERENV', 'SERVICE_NAME') as service_name,
sys_context('USERENV', 'SERVER_HOST') as server_host
from dual;Compare every value with the environment you intended to use. This catches errors caused by similar development, test, and production service names.
Exercise
You receive ORA-12154 when connecting with ORCLPDB, but the full Easy Connect string works. Which layer should you investigate?
Show answer
Investigate connect-identifier resolution, especially the alias spelling and the tnsnames.ora file selected by the client.