使用 System.Data.OracleClient 时如何指定要使用的 Oracle Home
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1461376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I specify the Oracle Home to use when using System.Data.OracleClient
提问by d4nt
I'm working on an Excel Addin (VSTO) in .NET that connects to an Oracle 10g database.
我正在 .NET 中处理连接到 Oracle 10g 数据库的 Excel 插件 (VSTO)。
I'm running on Vista x64 and have figured out that I need both the x86 and x64 Oracle clients installed on my machine so that both 32 bit processes (like PL/SQL Developer) and 64 bit processes (like an example .NET console app compiled for "Any CPU") can connect to Oracle.
我在 Vista x64 上运行并发现我需要在我的机器上安装 x86 和 x64 Oracle 客户端,以便 32 位进程(如 PL/SQL Developer)和 64 位进程(如示例 .NET 控制台应用程序)为“任何 CPU”编译)可以连接到 Oracle。
That's all working fine. My problem is that Excel is a 32 bit app hosting a .NET DLL and, according to ProcessMonitorthe excel process is loading the "OraClient10g_home1" Oracle client at "C:\oracle\product\10.2.0\client_1\BIN\oci.dll" (which happens to be the 64 bit client) and that gives me a BadImageFormatException when my .NET code tries to use it.
这一切正常。我的问题是 Excel 是一个托管 .NET DLL 的 32 位应用程序,并且根据ProcessMonitor的说法,excel 进程正在加载位于“C:\oracle\product\10.2.0\client_1\BIN\oci”的“OraClient10g_home1”Oracle 客户端。 dll”(恰好是 64 位客户端),当我的 .NET 代码尝试使用它时,它会给我一个 BadImageFormatException 。
What I want is to tell .NET to load the 32 bit "OraClient10g_home2" Oracle client (i.e. "C:\oracle\product\10.2.0\client_2\BIN\oci.dll"). How can I tell .NET to use client_2 instead of client_1.
我想要的是告诉 .NET 加载 32 位“OraClient10g_home2”Oracle 客户端(即“C:\oracle\product\10.2.0\client_2\BIN\oci.dll”)。我如何告诉 .NET 使用 client_2 而不是 client_1。
采纳答案by Blair
Try changing the DllPath in HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOME\ODP.NET.
尝试更改 HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOME\ODP.NET 中的 DllPath。
回答by Mac
You could :
你可以 :
- change your
%PATH%
before the oracle client is loaded (usingSetEnvironmentVariable
). - use Oracle Instant Clientinstead. Some advantages are summarized here(bottom line : you can make sure which oracle client is going to be used by your application).
%PATH%
在加载 oracle 客户端之前更改您的(使用SetEnvironmentVariable
)。- 请改用Oracle Instant Client。这里总结了一些优点(底线:您可以确定您的应用程序将使用哪个 oracle 客户端)。