C# 在 64 位机器上以 32 位模式运行 Oracle 客户端

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16538561/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 01:17:08  来源:igfitidea点击:

Run Oracle Client in 32-bit mode on a 64-bit machine

c#oraclevisual-studiovisual-studio-200832bit-64bit

提问by Joseph

I have just moved from a 32-bit Windows 7 desktop to a 64-bit Windows 7 Laptop. We have a C# program that we are developing that contains approximately 60 projects within the solution. I keep getting the following error whilst trying to build:

我刚刚从 32 位 Windows 7 桌面转移到了 64 位 Windows 7 笔记本电脑。我们正在开发一个 C# 程序,其中包含解决方案中的大约 60 个项目。我在尝试构建时不断收到以下错误:

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

Obviously the error is quite self explanatory and I am trying to get my whole solution to load in 32 bit mode. I have gone through every single project and set the target platform to x86 but I am still getting this error. I have searched Google and seen countless different approaches, but I cant seem to fix this problem. What is the best way to ensure my project is running in 32-bit mode on a 64-bit machine?

显然,错误是不言自明的,我试图让我的整个解决方案以 32 位模式加载。我已经完成了每个项目并将目标平台设置为 x86,但我仍然收到此错误。我搜索了谷歌并看到了无数不同的方法,但我似乎无法解决这个问题。确保我的项目在 64 位机器上以 32 位模式运行的最佳方法是什么?

I am using Visual Studio 2008. I am currently considering downgrading to 32-bit but really want to avoid having to do this.

我正在使用 Visual Studio 2008。我目前正在考虑降级到 32 位,但真的想避免这样做。

采纳答案by Belogix

I found that you have to install the 32-bit Oracle client (you can download the installerfrom their website) even if you are running on a 64-bit machine.

我发现即使您在 64 位机器上运行,您也必须安装 32 位 Oracle 客户端(您可以从他们的网站下载安装程序)。

In addition, during the discussions people were talking about 32-bit mode etc. This is how you can check / set that for an IIS 7 hosted application. You shouldn't need to change this but I have added here for completeness / future reference.

此外,在讨论期间,人们在谈论 32 位模式等。这是您可以检查/设置 IIS 7 托管应用程序的方式。您不需要更改此设置,但为了完整性/将来参考,我已在此处添加。

  • Launch IIS 7 and expand the server name node.
  • Click on Application Poolsnode and find the application Pool you are using.
  • On the right-hand panel click Advanced Settings...
  • In the pop-up box that appears check Enabled 32-Bit Applicationssetting which is third option from the top.
  • 启动 IIS 7 并展开服务器名称节点。
  • 单击应用程序池节点并找到您正在使用的应用程序池。
  • 在右侧面板上单击高级设置...
  • 在出现的弹出框中选中启用 32 位应用程序设置,这是从顶部开始的第三个选项。

回答by Piotr Stapp

You have to change your main .exe file to run only as 32-bit. You can do this in Visual Studio - just change Platform targetfrom "Any CPU" to "x86".

您必须将主 .exe 文件更改为仅作为 32 位运行。您可以在 Visual Studio 中执行此操作 - 只需将平台目标从“任何 CPU”更改为“x86”。

If this is not possible, use corflags.exe which forces an existing exe to be a 32-bit application.

如果这是不可能的,请使用 corflags.exe,它会强制现有的 exe 成为 32 位应用程序。

回答by zeroend

I have been struggling with this issue for months now and finally solved it. I think all the posts are helpful, but I had one missing piece. I didn't have a Microsoft ODBC for Oracle instance setup for User DSN or System DSN. I'm working on a Windows 8 machine. So for me I had to go to the general windows search and type in ODBC and open the ODBC Data Source Administrator (32-bit). Check to see if you have a Microsoft ODBC for Oracle setup on the User DSN tab or the System DSN tab. If not click on Add and select Microsoft ODBC for Oracle. Fill out the info for your datasource you are trying to hit and click ok. Make sure to restart your computer and that is what finally worked for me. Hope this helps some of you.

我几个月来一直在为这个问题苦苦挣扎,终于解决了。我认为所有的帖子都有帮助,但我遗漏了一个。我没有为用户 DSN 或系统 DSN 设置用于 Oracle 实例的 Microsoft ODBC。我正在使用 Windows 8 机器。所以对我来说,我必须转到常规 Windows 搜索并输入 ODBC 并打开 ODBC 数据源管理器(32 位)。检查您是否在“用户 DSN”选项卡或“系统 DSN”选项卡上安装了 Microsoft ODBC for Oracle。如果没有单击添加并选择 Microsoft ODBC for Oracle。填写您尝试点击的数据源的信息,然后单击确定。确保重新启动计算机,这最终对我有用。希望这对你们中的一些人有所帮助。

回答by user3906334

In my case 64 bit Oracle client was installed on my machine but still giving same error. So, I have analyse that in my application go to Application right click go to ->Properties->Web tab and uncheck the "Use IIS Express" option if you are using local IIS Web server. Problem got solved.

在我的情况下,我的机器上安装了 64 位 Oracle 客户端,但仍然出现相同的错误。因此,我分析了在我的应用程序中,如果您使用的是本地 IIS Web 服务器,请转到应用程序右键单击转到 -> 属性 -> Web 选项卡并取消选中“使用 IIS Express”选项。问题解决了。

回答by user7597235

You have to change your main .exe file to run only as 32-bit. You can do this in Visual Studio - just change Platform target from "Any CPU" to "x86". https://msdn.microsoft.com/en-us/library/ms185328.aspx

您必须将主 .exe 文件更改为仅作为 32 位运行。您可以在 Visual Studio 中执行此操作 - 只需将平台目标从“任何 CPU”更改为“x86”。 https://msdn.microsoft.com/en-us/library/ms185328.aspx