Learn the cause and how to resolve the ORA-12154 error message in Oracle.
When you encounter an ORA-12154 error, the following error message will appear:
- ORA-12154: TNS:could not resolve service name
You tried to connect to Oracle, but the service name is either missing from the TNSNAMES.ORA file or is incorrectly defined.
The option(s) to resolve this Oracle error are:
Make sure that the TNSNAMES.ORA file exists and is in the correct directory.
In my case, <My directory>:\app\mudassir.shahzad\product\11.1.0\client_1\Network\Admin
Make sure that there is a file named “sqlnet.ora” in your ..Network>Admin and it contains “TNSNAMES” as a value for “NAMES.DIRECTORY_PATH” property.
If the file is not there, you can copy it from the Sample folder or create a new file named “sqlnet.ora” and copy the following:
# Every line that begins with # is a comment line
# You can modify the entry below for your own database.
# sqlnet.ora Network Configuration File
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
Make sure that the service name that you are connecting to is included in the TNSNAMES.ORA file and that it is correctly defined.
Now, go easy with this. Make sure that there are no syntax errors in the TNSNAMES.ORA file. For example, if there are unmatched brackets in the file (ie: open bracket without the corresponding close bracket), the file will be rendered unusable.
You may think that your file is correct but it might be not. Even an extra space character can cause the error (happened to me, took me a bloody day to figure out!)