.net 当安装程序未创建标准 DSN 时,如何在 64 位 Server 2008 上使用 32 位 ODBC 驱动程序?

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

How do I use a 32-bit ODBC driver on 64-bit Server 2008 when the installer doesn't create a standard DSN?

.netodbc32bit-64bitregistry

提问by tvanfosson

I ran into an issue with some third party software that we use to track software license usage in our computer labs. We recently migrated the app to 64-bit Server 2008 after receiving assurances from the company that it was compatible and running some preliminary tests that showed that the app worked in the 64-bit environment. Unfortunately the person doing the testing didn't test the functionality of a couple of apps that I have that rely on accessing the data to do both live- and post-processing on the data to produce some reports.

我遇到了一些我们用来跟踪计算机实验室中软件许可证使用情况的第三方软件的问题。我们最近将应用程序迁移到 64 位 Server 2008,在收到公司保证它是兼容的并运行一些初步测试后,表明该应用程序可以在 64 位环境中运行。不幸的是,进行测试的人没有测试我拥有的几个应用程序的功能,这些应用程序依赖于访问数据对数据进行实时和后处理以生成一些报告。

Turns out that the application doesn't have a 64-bit ODBC driver to access its internal data and can't use a 64-bit SQL Server ODBC driver to export its data to SQL server. It does include and install a 32-bit ODBC driver, but it installs it as a User Data Source, not a System Data Source, meaning that my windows service that runs the live collection isn't able to find it. I'm also not able to create a System DSN since the Data Sources admin console can't find the installed driver.

事实证明,该应用程序没有 64 位 ODBC 驱动程序来访问其内部数据,并且无法使用 64 位 SQL Server ODBC 驱动程序将其数据导出到 SQL Server。它确实包含并安装了 32 位 ODBC 驱动程序,但它将其安装为用户数据源,而不是系统数据源,这意味着我运行实时集合的 Windows 服务无法找到它。我也无法创建系统 DSN,因为数据源管理控制台找不到安装的驱动程序。

My question is how do I configure a data source for this connection that I can access from a C#/.NET windows service running under a system account?

我的问题是如何为这个连接配置一个数据源,我可以从在系统帐户下运行的 C#/.NET Windows 服务访问它?

Since I've figured out a way to do it, I'll provide my solution as an answer (in keeping with the FAQon how to answer your own question).

由于我已经找到了一种方法,因此我将提供我的解决方案作为答案(与有关如何回答您自己的问题的常见问题解答保持一致)。

Similar to: What software exists for bridging a 64-bit ODBC app to a 32-bit ODBC driver on windows?

类似于: 有 什么软件可以将 64 位 ODBC 应用程序桥接到 Windows 上的 32 位 ODBC 驱动程序?

回答by tvanfosson

It turns out that you can create 32-bit ODBC connections using C:\Windows\SysWOW64\odbcad32.exe. My solution was to create the 32-bit ODBC connection as a System DSN. This still didn't allow me to connect to it since .NET couldn't look it up. After significant and fruitless searching to find how to get the OdbcConnection class to look for the DSN in the right place, I stumbled upon a web site that suggested modifying the registry to solve a different problem.

事实证明,您可以使用C:\Windows\SysWOW64\odbcad32.exe. 我的解决方案是创建 32 位 ODBC 连接作为系统 DSN。这仍然不允许我连接到它,因为 .NET 无法查找它。在寻找如何让 OdbcConnection 类在正确的位置查找 DSN 进行了大量而徒劳的搜索之后,我偶然发现了一个网站,该网站建议修改注册表以解决​​不同的问题。

I ended up creating the ODBC connection directly under HKLM\Software\ODBC. I looked in the SysWOW6432 key to find the parameters that were set up using the 32-bit version of the ODBC administration tool and recreated this in the standard location. I didn't add an entry for the driver, however, as that was not installed by the standard installer for the app either.

我最终直接在HKLM\Software\ODBC. 我查看了 SysWOW6432 密钥以找到使用 32 位版本的 ODBC 管理工具设置的参数,并在标准位置重新创建了它。但是,我没有为驱动程序添加条目,因为该应用程序的标准安装程序也未安装该条目。

After creating the entry (by hand), I fired up my windows service and everything was happy.

创建条目(手动)后,我启动了我的 Windows 服务,一切都很愉快。

回答by Parag Vyas

Open IIS manager, select Application Pools, select the application pool you are using, click on Advanced Settings in the right-hand menu. Under General, set "Enable 32-Bit Applications" to "True".

打开IIS管理器,选择Application Pools,选择你正在使用的应用程序池,点击右侧菜单中的Advanced Settings。在常规下,将“启用 32 位应用程序”设置为“真”。

回答by Baddack

A lot of these answers are pretty old, so I thought I would update with a solution that I think is helpful.

很多这些答案都很旧,所以我想我会更新一个我认为有用的解决方案。

Our issue was similar to OP's, we upgraded 32 bit XP machines to 64 bit windows 7 and our application software that uses a 32 bit ODBC driver stopped being able to write to our database.

我们的问题与 OP 类似,我们将 32 位 XP 机器升级到 64 位 Windows 7,我们使用 32 位 ODBC 驱动程序的应用程序软件停止写入我们的数据库。

Turns out, there are two ODBC Data Source Managers, one for 32 bit and one for 64 bit. So I had to run the 32 bit version which is found in C:\Windows\SysWOW64\odbcad32.exe. Inside the ODBC Data Source Manager, I was able to go to the System DSN tab and Add my driver to the list using the Add button. (You can check the Drivers tab to see a list of the drivers you can add, if your driver isn't in this list then you may need to install it).

事实证明,有两个 ODBC 数据源管理器,一个用于 32 位,一个用于 64 位。所以我必须运行 C:\Windows\SysWOW64\odbcad32.exe 中的 32 位版本。在 ODBC 数据源管理器中,我可以转到系统 DSN 选项卡并使用添加按钮将我的驱动程序添加到列表中。(您可以检查“驱动程序”选项卡以查看您可以添加的驱动程序列表,如果您的驱动程序不在此列表中,那么您可能需要安装它)。

The next issue was the software that we ran was compiled to use 'Any CPU'. This would see the operating system was 64 bit, so it would look at the 64 bit ODBC Data Sources. So I had to force the program to compile as an x86 program, which then tells it to look at the 32 bit ODBC Data Sources. To set your program to x86, in Visual Studio go to your project properties and under the build tab at the top there is a platform drop down list, and choose x86. If you don't have the source code and can't compile the program as x86, you might be able to right click the program .exe and go to the compatibility tab and choose a compatibility that works for you.

下一个问题是我们运行的软件被编译为使用“任何 CPU”。这将看到操作系统是 64 位,因此它会查看 64 位 ODBC 数据源。所以我不得不强制程序编译为 x86 程序,然后告诉它查看 32 位 ODBC 数据源。要将您的程序设置为 x86,请在 Visual Studio 中转到您的项目属性,在顶部的构建选项卡下有一个平台下拉列表,然后选择 x86。如果您没有源代码并且无法将程序编译为 x86,您可以右键单击程序 .exe 并转到兼容性选项卡并选择适合您的兼容性。

Once I had the drivers added and the program pointing to the right drivers, everything worked like it use to. Hopefully this helps anyone working with older software.

一旦我添加了驱动程序并且程序指向正确的驱动程序,一切都像以前一样工作。希望这可以帮助任何使用旧软件的人。