Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 803
ChernikovP Avatar asked Jun 13 '26 11:06

ChernikovP


1 Answers

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.

like image 128
ialekseev Avatar answered Jun 16 '26 04:06

ialekseev