Sub topic 13
Troubleshooting common connection errors
This chapter assumes you can already connect with SQL Developer and SQLcl when everything is correct. It also assumes you know the parts of a connection: host, port, service name, and credentials. Here you will learn to read the error code, decide which layer failed, and fix it.
Read the error as a layer report
A connection attempt passes through three layers in order. Each layer produces its own family of errors, so the code tells you where to look.
- Name resolution. The client turns your connect identifier (Easy Connect string, TNS alias, or JDBC URL) into a host, port, and service name.
- Network and listener. The client reaches the host and port. The listener then hands the request to a registered service.
- Authentication. The database checks the username, password, and account status.
An error that appears in the first layer cannot be fixed by changing a password. Checking the layer first saves time.
The four errors you will meet most
| Error | Message | Layer | Most likely cause |
|---|---|---|---|
| ORA-12154 | TNS:could not resolve the connect identifier specified | Name resolution | Alias missing from `tnsnames.ora`, or the client reads a different `tnsnames.ora` than you expect |
| ORA-12541 | TNS:no listener | Network | Wrong host or port, listener stopped, or a firewall blocks the port |
| ORA-12514 | TNS:listener does not currently know of service requested | Listener | Wrong service name, or the database has not yet registered the service |
| ORA-01017 | invalid username/password; logon denied | Authentication | Wrong password, wrong case, or special characters mangled by the shell |
ORA-12154: the alias cannot be resolved
This error means the client never got as far as contacting a host. When you type hr@ORCLPDB, the client looks for the alias ORCLPDB. It searches the directory named by the TNS_ADMIN environment variable first, then the default network admin directory of the client installation.
Common causes:
- The alias is misspelled, or the entry is missing.
TNS_ADMINpoints to a different directory than the one you edited.- The
tnsnames.orafile has a syntax error, such as unbalanced parentheses. The client then ignores the entry. - In SQL Developer, the Connection Type is TNS but no Tnsnames Directory is configured. Set it under Tools > Preferences > Database > Advanced > Tnsnames Directory.
Here is an entry that works. Compare your file against it, paying attention to parentheses:
ORCLPDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = dbhost.example.com)(PORT = 1521))
(CONNECT_DATA = (SERVICE_NAME = orclpdb1.example.com))
)To prove the problem is resolution and not the database, bypass the alias with Easy Connect. If this works, the database is fine and the alias setup is the problem:
sql hr@//dbhost.example.com:1521/orclpdb1.example.comOn a machine with a full Oracle client, tnsping ORCLPDB shows which tnsnames.ora was read and whether the host answers. SQLcl does not ship tnsping, so the Easy Connect test is your substitute.
ORA-12541: nothing is listening
The client resolved the identifier and tried the host and port, but no listener answered. Work from the outside in:
- Check the host name and port in your connect string. A typo in either gives this error.
- Check that the host is reachable and the port is open from your machine, for example with
nc -zv dbhost.example.com 1521on Linux or macOS. In PowerShell, useTest-NetConnection dbhost.example.com -Port 1521. - On the database server, run
lsnrctl status. If the listener is down, start it withlsnrctl start.
A firewall that silently drops packets may instead produce a timeout such as ORA-12170 (connect timeout occurred). Treat that as the same family of problem: the packets never reach a listener.
ORA-12514: the listener does not know the service
Here the network path works. The listener answered, but it has no service registered under the name you gave. This is the error that most often follows a copy-paste of the wrong name, for example using the container database name instead of the pluggable database service.
On the server, list what the listener knows:
lsnrctl servicesLook for lines such as Service "orclpdb1.example.com" has 1 instance(s). Your connect string must use one of those names exactly. If you can already connect through another route, you can also ask the database:
select name, network_name
from v$services
order by name;Two further causes are worth knowing:
- The database or pluggable database was just started. Services register with the listener shortly after startup, so wait a minute and retry.
- The pluggable database is closed. Open it with
alter pluggable database orclpdb1 open;while connected as a privileged user to the container.
A related error, ORA-12505, means the listener does not know the SID you supplied. This happens when a string such as host:1521:orcl (SID syntax) is used against a database that only registers a service name. Prefer service names, as the earlier chapters showed.
ORA-01017: the database rejected the credentials
If you see this, you have already reached the database, so the host, port, and service are correct. Check these in order:
- Case. Passwords are case-sensitive in current releases. Check whether Caps Lock is on.
- Where you typed it. Prefer the interactive prompt, which avoids shell interpretation:
sql /nolog
SQL> connect hr@//dbhost.example.com:1521/orclpdb1.example.com
Password? (**********?) ********
Connected.- Special characters. A password containing
@,/, or spaces breaks theuser/password@identifierform, because the parser reads@as the start of the identifier. Wrap the password in double quotes inside SQLcl, as inconnect hr/"My@Pass word"@//dbhost.example.com:1521/orclpdb1.example.com. On a shell command line you must also protect the quotes from the shell, which is one more reason to use the prompt. - The right database. The same username can exist in several pluggable databases with different passwords. A connection that reached the wrong service gives ORA-01017 even with a correct password. Verify the service name first.
Repeated failures can lock the account. ORA-28000 (the account is locked) and ORA-28001 (the password has expired) are authentication errors with a different cause. A database administrator fixes them with alter user hr account unlock; or a password change.
Confirm where you actually landed
When a connection succeeds but the data looks wrong, the problem is often that you connected to a different service or user than you intended. This query reports the session's user, service, and server host:
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;Run it after every new connection setup. A mismatch between service_name and what you intended means your alias or saved connection points at the wrong place.
Errors specific to each tool
SQL Developer
- The Test button in the connection dialog shows
Status: Successor the Oracle error text. Test before you click Connect, because the dialog shows the full message. - A saved connection keeps the old host and port after you move a database. Edit the connection, or create a new one, and test again.
- If the Test button is slow and then reports a timeout, suspect the network layer (ORA-12170) before you suspect SQL Developer.
SQLcl
- A script that hangs at a login prompt in automation is usually a failed login waiting for input. The
-Loption limits SQLcl to one login attempt so the run fails instead of waiting:
sql -S -L hr@orclpdb @report.sql- With a cloud wallet, a failure right after
set cloudconfignormally means a wrong path to the wallet zip or a service alias that is not in the wallet. Open the wallet'stnsnames.oraand copy an alias exactly, such asmydb_high.
SQL> set cloudconfig /path/to/Wallet_MYDB.zip
SQL> connect admin@mydb_highA repeatable method
- Copy the exact error code and message.
- Match it to a layer using the table above.
- Reduce the problem: replace the alias with an Easy Connect string, and type the password at the prompt.
- Run one check for that layer (
lsnrctl status,lsnrctl services, or the verification query). - Change one thing at a time, then retest.
Exercise
You run sql hr@//dbhost.example.com:1521/orcl.example.com and get ORA-12514. Running nc -zv dbhost.example.com 1521 reports the port is open. What does this tell you, and what is your next step?
Show answer
The network path and the listener are working, because a listener answered. The listener has no service named orcl.example.com registered. Run lsnrctl services on the server, find the exact service name (for example orclpdb1.example.com), and use it in the connect string. Also check that the pluggable database is open and was not just restarted.
Exercise
A colleague's password contains an @ character. connect hr/Pa@ss1@//dbhost.example.com:1521/orclpdb1.example.com fails with ORA-01017 even though the password is correct. Give two fixes.
Show answer
First, type the password at the prompt by running connect hr@//dbhost.example.com:1521/orclpdb1.example.com and entering it when asked. Second, put the password in double quotes: connect hr/"Pa@ss1"@//dbhost.example.com:1521/orclpdb1.example.com. The unquoted form makes the parser treat the first @ as the start of the connect identifier.
Exercise
connect hr@ORCLPDB fails with ORA-12154, but the Easy Connect form of the same database works. Name two things to check.
Show answer
Check that the alias ORCLPDB exists, spelled exactly, in the tnsnames.ora that the client reads, and that its parentheses are balanced. Also check that the TNS_ADMIN environment variable points to the directory containing that file. In SQL Developer, check that the Tnsnames Directory preference is set.