Fix ORA-12154: TNS Could Not Resolve Connect Identifier
Getting this error when connecting to Oracle? It means SQL Developer can't find the database alias in your TNS configuration. Here's how to fix it.
What ORA-12154 Means
Understanding the error
This error occurs when Oracle can't find the TNS alias (database name) you're trying to connect to.
Oracle looks for this alias in the tnsnames.ora file, and either:
- The alias doesn't exist in tnsnames.ora
- The tnsnames.ora file can't be found
- There's a typo in the alias name
- The tnsnames.ora file has syntax errors
Quickest Fix: Use Basic Connection
Skip TNS entirely - connect directly
Instead of using a TNS alias, you can connect directly using the hostname, port, and service name. This bypasses tnsnames.ora completely:
Open Connection Dialog
Click the green + icon in Connections panel. Make sure you're on the Oracle tab.
Select "Basic" Connection Type
In the Connection Type dropdown, select Basic instead of TNS.
Enter Direct Details
Hostname: Your Oracle server
Port: 1521 (default)
Service name: Your database service name (e.g., ORCL, XE, or your PDB name)
If You Must Use TNS
Fix your TNS configuration
1. Check TNS_ADMIN Environment Variable
SQL Developer needs to know where to find tnsnames.ora. Set the TNS_ADMIN variable:
Windows: Set TNS_ADMIN=C:\oracle\network\admin
Linux/Mac: export TNS_ADMIN=/opt/oracle/network/admin
Or in SQL Developer: Tools → Preferences → Database → Advanced → Tnsnames Directory
2. Verify Your tnsnames.ora Entry
A correct tnsnames.ora entry looks like this:
MYDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = myserver.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
Common mistakes: Missing parentheses, wrong indentation, spaces in the alias name, or using SID instead of SERVICE_NAME.
3. Check the Alias Name Exactly
The connection name in SQL Developer must match the alias in tnsnames.ora exactly. TNS aliases are case-insensitive, but check for:
- Extra spaces before or after the name
- Typos (PROD vs PRDO)
- Wrong environment (DEV vs PROD)
4. Test with tnsping
From command line, test if the TNS alias resolves:
tnsping MYDB
If tnsping fails, the problem is in your TNS configuration, not SQL Developer.
Other ORA-12154 Causes
Less common but possible issues
Multiple Oracle Homes
If you have multiple Oracle installations, SQL Developer might be looking at the wrong tnsnames.ora. Explicitly set the path in SQL Developer preferences.
File Permissions
Make sure your user account has read access to the tnsnames.ora file. On Windows, right-click the file and check Security permissions.
LDAP Configuration
If your organization uses LDAP for Oracle naming, check sqlnet.ora for the NAMES.DIRECTORY_PATH setting. It should include TNSNAMES.
Need SQL Developer?
Download free for Windows. Connect to Oracle, MySQL, PostgreSQL, and more.