Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set proper path to TNSNAMES file in C# application?

I have a program in C# that use ODP.NET dlls:

oci.dll, ociw32.dll, Oracle.DataAccess.dll,
orannzsbb11.dll, oraocci11.dll, oraociicus11.dll,
OraOps11w.dll. 

I've got 2 computers. First with whole ODAC package installed, and second without that package. But I have all required dlls in my exe directory, so ODAC is not a problem I think.

The difference between these computers is the path to the TNSNAMES file.

First: C:\app\OraHome_1\Network\admin\
Second: C:\Oracle\product\11.2.0\client_1\network\admin

On the first computer, the program works fine. But on the second one with the same connection string, I get the error:

cannot open connection (ORA-12154)

Using SQL Plus I can connect on both computers. How can I show my program the proper path to the tnsnames.ora file?

like image 911
Marshall Avatar asked May 16 '12 12:05

Marshall


1 Answers

You can set the TNS_ADMIN environment variable programmatically. See this page for a step by step. That is if you wanted to change to a specific TNS_NAMES.ORA file. The Oracle Client must still be installed on the client machine.

From ConnectionStrings - without using TNS:

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


EDIT: Added 3rd option

Please see this question which could aid you in finding the current location of the client's TNS_NAMES.ORA file - which you could open and modify if you wish (add your own connection if it doesn't exist)

like image 193
SQLMason Avatar answered Oct 04 '22 19:10

SQLMason