如何设置在C#应用程序中TNSNAMES文件正确的路径? [英] How to set proper path to TNSNAMES file in C# application?
问题描述
下面是我的问题:
我已经在C#程序使用ODP.NET dll文件:OCI.DLL,OCIW32.DLL,Oracle.DataAccess.dll,orannzsbb11.dll,oraocci11.dll,oraociicus11。 DLL,OraOps11w.dll。
here is my problem: I've a program in C# that use ODP.NET dlls: oci.dll, ociw32.dll, Oracle.DataAccess.dll, orannzsbb11.dll, oraocci11.dll, oraociicus11.dll, OraOps11w.dll.
我有2台电脑。首先用全ODAC软件包安装,和第二没有这种包。但是,我有我的exe文件目录中的所有必需的DLL,所以ODAC是没有问题的(我认为)。
这些计算机之间的差别是路径TNSNAMES文件。
第一:C:\app\OraHome_1\Network\admin\
二C:\Oracle\product\11.2.0\client_1\\\
etwork\admin
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 path to TNSNAMES file. First: C:\app\OraHome_1\Network\admin\ Second: C:\Oracle\product\11.2.0\client_1\network\admin
和第一次CPU的程序工作正常。但在第二个具有相同的连接字符串,开放粗野,连接(ORA-12154)。并使用SQL另外,我可以连接两台计算机上。
And on first cpu program works fine. But on the second one with the same connection string, connot open connection (ORA-12154). And using SQL Plus I can connect on both computers.
所以,我怎么能证明我的程序TNSNAMES正确的路径?
So, how can I show my program the proper path to TNSNAMES?
推荐答案
您可以通过编程设定 TNS_ADMIN
环境变量。看到这个页面的步步。也就是说,如果你想改变一个特定的 TNS_NAMES.ORA
文件。仍必须安装在客户端计算机上的Oracle客户端。
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.
的ConnectionStrings - 不使用TNS:
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;
修改新增3选项
请看到这问题它可以帮助你在寻找客户的 TNS_NAMES.ORA
文件的当前位置 - 你可以打开,如果你想修改(添加自己的连接,如果它不存在)
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)
这篇关于如何设置在C#应用程序中TNSNAMES文件正确的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!