ChernikovP
ChernikovP

Reputation: 471

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?

Upvotes: 2

Views: 12162

Answers (4)

Patrick Hofman
Patrick Hofman

Reputation: 156968

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.

Upvotes: 3

Christian Shay
Christian Shay

Reputation: 2635

Copy over the TNSNAMES.ORA that contained data.customer.com into your {ODP.NET ORACLE HOME}/NETWORK/ADMIN directory if you used the Oracle installer to install ODP.NET and it should work because the installer sets TNS_ADMIN variable in the machine.config, (for Managed ODP.NET).

You can also use SQLNET EZ Config connection string syntax if you want to do without the TNSNAMES.ORA entry altogether.

For example: Data Source=MyHost:MyPort/MyOracleService;User Id=myUsername;Password=myPassword;

Upvotes: 0

alekseevi15
alekseevi15

Reputation: 1782

Personally, I prefer not to depend on defined tnsnames.ora on a machine. Using longer connection string(see example below) you could deploy your program not thinking about tnsnames.ora that may not exist on a target system.

Example of using ODP.NET without tnsnames.ora:

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

See also.

Upvotes: 4

kevvy_dawg
kevvy_dawg

Reputation: 23

I have recently ventured down this road, only to run into 32x/64x issues when running attempting to run a web site using ODP.net.

Here is my working connection string: Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=ip/server)(PORT=port)))(CONNECT_DATA=(SERVER=DEDICATED)(SID=service_id)));User Id=user_id;Password=p_word"

EDIT: Darn, @ialekseev is too fast..

Upvotes: 2

Related Questions