ASP.NET / Oracle issue: TNS Could not resolve the connect identifier specified

Make sure you have installed the Oracle Database client (x86 or x64).

Make sure you have the PATH configured to use the Oracle bin folder:

PATH=C:\Oracle\product\11.2.0\client_1\bin

Make sure your tnsnames.ora file is in the directory:

C:\Oracle\product\11.2.0\client_1\network\admin

You can try and use the following connection string:

Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.1)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=MYDATABASE)));User ID=myusername;Password=mypassword;

UPDATE:

I don't have this environment variable (cause I use the extended connection string) but someone here and here suggest to add TNS_ADMIN.


Using TNS:

(For ASP.NET Core you need the TNS_ADMIN environment variable pointing to the directory where tnsnames.ora is located)

Data Source = TORCL; User Id = myUsername; Password = myPassword;

Not using TNS:

Data Source = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = MyHost) (PORT = MyPort))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = MyOracleSID));
User Id = myUsername; Password = myPassword;

If all the above validations fail, try the following. This is what solved my issue. It is the name of the TNS entry in tnsnames.ora file.

Example: I had abc.xyz = (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort))(CONNECT_DATA=(SERVICE_NAME=MyOracleSID)));

I still got ORA-12154: TNS:could not resolve the connect identifier specified

Then I changed it to, abcxyz = () and it worked.

Basically I removed special characters like . and _ in the TNS entry name.