Search code examples
.netoracleodp.net

Connection string in ODP.Net


Initially I was using oraoledb.oracle provider in order to connect to Oracle database and it was easy to build a connection string:

Provider=OraOLEDB.Oracle;User Id=myId;Password=myPassword;Data Source=data.customer.com

and everything works as it expected, but currently I switched to ODP.Net in order to get rid of installing oracle client and I get an error ORA-12154: TNS:could not resolve the connect identifier specified with the following connection string:

Data Source=data.customer.com;User Id=myId;Password=myPassword

So could someone tell me, where I made a mistake?


Solution

  • Managed ODP.NET works with tnsnames.ora, but it needs some additional configuration to work. That's your problem. You are trying to use a name from your tnsnames.ora which only works when setting the TNS_ADMIN environment variable or config section in your machine.config, Web.config, or app . config. Another option to be able to use the tnsnames.ora is to the unmanaged ODP.NET driver, which is a pain to use in my opinion.

    Try to use EZCONNECT names, which are supported by both the managed and unmanaged driver without the need for a tnsnames.ora file or any other configuration.