How to set the correct path to a TNSNAMES file in a C # application?

here is my problem: I have a C # program that uses oDP.NET dll dll: oci.dll, ociw32.dll, Oracle.DataAccess.dll, orannzsbb11.dll, oraocci11.dll, oraociicus11.dll, OraOps11w.dll.

I have 2 computers. First, the entire ODAC package is installed, and the second without this package. But I have all the necessary 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

And according to the first program, the processor works fine. But on the second with the same connection string, connot open connection (ORA-12154). And using SQL Plus, I can connect on both computers.

So, how can I show my program the correct path to TNSNAMES?

+5
source share
3 answers

You can programmatically change the environment variable TNS_ADMIN. See this page for step by step. That is, if you want to go to a specific file TNS_NAMES.ORA. 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 third option

Please see this question , which will help you find the current location of the client file TNS_NAMES.ORA, which you can open and modify if you want (add your own connection if it does not exist)

+11
source

TNSNames: ... , . , : DLL . ODP.Net , : , oracle ( tnsnames ).

, -, tnsnams. . :

Data Source= (DESCRIPTION =
      (ENABLE = BROKEN)
      (ADDRESS_LIST =
      (LOAD_BALANCE = ON)
      (FAILOVER = ON)
      (ADDRESS = (PROTOCOL = TCP)(Host =por10srv-a)(Port = 1521))
      )
      (CONNECT_DATA =
      (SERVICE_NAME = por10.gruppo.autostrade.it)
      (FAILOVER_MODE =
      (TYPE = SELECT)
      (METHOD = BASIC)
      (RETRIES = 10)
      (DELAY = 3)
      )
      )
      );User ID=npa_collaudo;Password=npa_collaudo;
+3

You do not need to install ODP.NET (or, in fact, Oracle Client), since you seem to have the necessary DLLs for the local distributive embedded Oracle client. In your case, it is possible that the TNSNAMES.ORA file is in the same folder as your executable file, and your specialized "inline oracle client" will select it from there. Otherwise, the oracle client local to your application will try to find it from any client installed on the computer.

+2
source

All Articles