TNS:could not resolve the connect identifier specified in .NET OracleClient
-
17-04-2021 - |
Question
Im using a .net OracleClient in my machine for connecting to a Database in Oracle. When im trying to connect its showing this TNS Error.
Now, I have edited the tnsnames.ora file and sqlnet.ora file. When I access the Oracle using a ServerExplorer. It gets connected to the Oracle Database and its fetching everything.
I do have a ODAC component from oracle website itself which also, i tried but dint worked.
My connection string is<add name="netOracleClient" connectionString="Data Source=ff.WORLD;Persist Security Info=True;User ID=vlc;Password=vlc;Unicode=True"
providerName="System.Data.OracleClient" />
<add name="ConnectionString" connectionString="DATA SOURCE=ff.WORLD;PASSWORD=vlc;USER ID=vlc"
providerName="Oracle.DataAccess.Client" />
I tried with ServerExplorer in both the components. Its working FINE with Server explorer and im getting the datas too. But when i write the code its throwing me this error ORA-12154: TNS:could not resolve the connect identifier specified
This is the code from which Im trying to connect.
OracleConnection con = new OracleConnection(WebConfigurationManager.ConnectionStrings["netOracleClient"].ConnectionString);
Tell me a way to resolve this???
NOTE: We have machines here itself from which we are accesing the same database with the same TNS using OracleClient for .net. I also wants to use the same..
Please Help me in this.
Solution
Now Its working for me. The steps we followed for doing this.
- We noticed we were having more than One TNSNames.ORA file.
- Then we could find it was pointing to Oracle Client version 8.x.So it was not working properly. So for working with it...
We removed all the ORacle Client Versions(since we were not able to point VisualStudio Oracle Client to a newer version)
Re-Installed it again. After a Restart it started Working.
OTHER TIPS
We have ODAC working fine with this connection string,
<ConnectionString name="ServerConnection">Data Source=PROD;User Id=DBUSER1;Password=DBPASSWORD1;Pooling=False;</ConnectionString>
together with the tnsnames.ora defining the Data Source - PROD same like in the sample tnsnames.ora file in the Oracle/Network/Admin folder.
tnsnames.ora entry goes like this
DDSENT3 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.15.10)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = DDSENT3)
)
)
Try adding the following to your web.config
:
<oracle.manageddataaccess.client>
<version number="*">
<settings>
<!-- Set this path if you are using TNS aliases as connection strings (not recommended) -->
<!-- Instead you can use "SERVER_NAME:PORT/SERVICE_NAME" as your data source -->
<setting name="TNS_ADMIN" value="C:\oracle\product\11.2.0\client_3\Network\Admin\"/>
</settings>
...
Just add your folder location, of course.