如何告诉 System.Data.OracleClient 使用 64 位 Oracle 驱动程序
我正在尝试在 Win7 x64 工作站上运行使用 System.Data.OracleClient 的 .NET 应用程序。工作站安装了 32 位 Oracle 客户端,这会导致以下错误消息:
尝试加载 Oracle 客户端库时抛出 BadImageFormatException。在安装了 32 位 Oracle 客户端组件的 64 位模式下运行时会出现此问题。
所以这是我漫长的尝试和失败之旅:
- 我尝试安装Oracle客户端win64_11gR2_client。但在设置过程中它崩溃了,没有任何评论。
- 我遵循 来自不同SO线程的答案,尝试并提取了instantclient-basic-windows.x64-11.2.0.2.0,并将包含二进制文件的文件夹放入 Windows PATH 变量中。但我仍然收到相同的错误消息(即使重新启动后)。
- 我遵循 这个答案并复制文件oci.dll、orannzsbb11.dll和oraociei11.dll 放入我的网站项目的 bin/ 文件夹中。还是一样的错误信息。
- 我尝试将即时客户端中的所有文件复制到该目录中,然后再次尝试,但没有成功。
- 我安装了ODAC112021Xcopy_x64.zip
- 我把希望寄托在 这个答案并查看了注册表中的DllPath(实际上应该与ODP.NET相关,而不是
System.Data.OracleClient
),并看到 DllPath 指向 ODAC 的正确 x64 安装,因此,如果我的应用程序未使用System.Data.OracleClient
,它应该工作,b但由于它确实使用了它,所以它仍然失败。 - 我用谷歌搜索和 stackoverflew 但没有找到我已经提到的帖子之外的任何内容。
- 我精心设计了这个 SO 问题,希望能从开明的 SO 用户那里得到任何有见地的建议。
从 b_levitt 得到第一个答案后,我尝试将以下行添加到
Application_Start
处的 Global.asax 中:Environment.SetEnvironmentVariable("ORACLE_HOME", @"C:\OracleProducts\Odac-11.2.0.2.1-x64"); Environment.SetEnvironmentVariable("PATH", @"C:\OracleProducts\Odac-11.2.0.2.1-x64;C:\OracleProducts\Odac-11.2.0.2.1-x64\bin");
C:\OracleProducts\Odac-11.2.0.2.1-x64 是我安装 ODAC 64 位 xcopy 版本的位置。 也没有成功。
在相关说明中,我什至尝试强制我的 .NET 应用程序进入 32 位模式,但没有成功,但这是另一回事。我需要一个前瞻性的解决方案,这意味着 64 位。
I am trying to run a .NET application which uses System.Data.OracleClient
on a Win7 x64 workstation. The workstation has a 32bit Oracle client installed, which leads to the following error message:
Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.
So this is my long journey of tries and failures:
- I tried to install the Oracle client win64_11gR2_client. But during the setup process it crashes without any comment.
- I followed an answer from a different SO thread, tried and extracted the instantclient-basic-windows.x64-11.2.0.2.0, and put the folder containing the binaries in the windows PATH variable. I still get the same error message though (even after rebooting).
- I followed the "alternative way" from this answer and copied the files oci.dll, orannzsbb11.dll, and oraociei11.dll into the bin/ folder of my web site project. Still the same error message.
- I tried and copied all files from the instant client into that directory and tried again, without success.
- I installed ODAC112021Xcopy_x64.zip and put the installation folder and the bin folder in the windows PATH variable. No success.
- I put my hope on this answer and reviewed the DllPath in the registry (which is actually supposed to relate to ODP.NET as opposed to
System.Data.OracleClient
) and saw that DllPath points to the correct x64 installation of ODAC, so, if my application wasn't usingSystem.Data.OracleClient
, it should work,b but since it does use that, it still failed. - I googled and stackoverflew but didn't find anything else that the posts I already referred to.
- I carefully crafted this SO question in the hope of getting any insightful advice from an enlightened SO user.
After getting the first answer from b_levitt, I tried and added the following lines to the Global.asax at
Application_Start
:Environment.SetEnvironmentVariable("ORACLE_HOME", @"C:\OracleProducts\Odac-11.2.0.2.1-x64"); Environment.SetEnvironmentVariable("PATH", @"C:\OracleProducts\Odac-11.2.0.2.1-x64;C:\OracleProducts\Odac-11.2.0.2.1-x64\bin");
C:\OracleProducts\Odac-11.2.0.2.1-x64 is where I installed the ODAC 64 bit xcopy version. No success either.
On a related note, I even tried to force my .NET app into 32bit mode without success, but that's a different thing. I need a forward-looking solution, which means 64bit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的 #5 应该可以工作,但你还需要设置 ORACLE_HOME 环境变量。我已经这样做过很多次了,包括最近使用您正在使用的 xcopy 安装。请查看我的 xcopy 安装经验并让我知道您遇到了哪些额外错误。
就我而言,我是为 asp.net 设置它,但 winforms 更容易。您可以打开 cmd 窗口,使用“set”命令设置 PATH 和 ORACLE_HOME 环境变量,然后从同一 cmd 窗口运行您的应用程序。一旦解决了错误,您就可以使用Environment.SetEnvironmentVariable 在代码中设置它们。
根据记录,我确实避免在客户端计算机上安装 Oracle 客户端,而是通过 Web 服务处理所有业务逻辑。这样我只需要 Web 服务器上的 oracle 组件。
Your #5 should have worked but you also need to set the ORACLE_HOME environment variable. I've done this many times including recently with the very xcopy install that you are using. Please check out my experience with the xcopy install and let me know what kind of additional errors that you get.
In my case I was setting it up for asp.net, but winforms is even easier. You can open a cmd window, use the "set" command to set both the PATH and the ORACLE_HOME environment variables and then run your app from that same cmd window. Once you get the bugs worked out, you can use the Environment.SetEnvironmentVariable to set these within your code.
For the record, I do avoid installing the oracle client on client machines by handling all of the business logic via web services. That way I only need the oracle components on the web server.
我和你有同样的问题。我通过 Oracle 论坛和 stackoverflow 找到了大部分答案。我无法发布链接以供参考,但我可以给您一些尝试的东西。
看看异常是否消失。
仅供参考,Microsoft 将在不久的将来放弃对 Oracle 数据提供程序(在 ADO.NET 中)的支持。目前它可以通过 .NET 4 运行,但最好开始测试本机 Oracle 驱动程序。
I had the same problem you have. I found most of my answers through Oracle forums and here at stackoverflow. I can't post links for reference but I can give you some things to try out.
See if the exception goes away.
FYI, Microsoft is dropping Oracle data provider (in ADO.NET) support in the near future. It currently works through .NET 4, but it is a good idea to start testing the native Oracle drivers.