Win7 64bit 环境如何对32bit Office建立OleDB 连接

本文介绍在Win7 64位环境下,如何通过更改vb.net程序的编译目标平台来实现对32位Office的OLEDB连接。文章解释了64位应用程序无法直接使用Jet 4.0的原因,并提供了具体的解决办法。

Win7 64bit 环境如何对32bit Office建立OleDB 连接

64bitApp无法使用Jet.4.0提供者,跟有没有安装32bit Office没有关系,就算装了,如果.NET是以X64模式在运行的话,还是无法使用。因为只要你的.NET App安装到64位元的OS,一定会自动升级成X64模式运行,所以也一定不能使用JET.4.0

只有将你的vb.net程序的编译方式(编译时的目标平台)强制改成x86模式,让你的32bit程序在64位元OS上以模拟32bit的模式运行,才能成功调用到JET.4.0

   vb.net程序编译时的目标平台被设置为Any CPU (在64位元OS下就会自动用64位元运行),编译出来的App是无法调用到32位元的程序的(如:Jet.4.0)!这是因为寻址不同, 64位元程序无法"呼叫"32位元程序;而32位元的程序却可以在64bit OS"上面运行",因为windows有一种WOW64模式,可以模拟32bit的模式,让你的32bit程序在64位元OS上运行。

 【参考】

.NET的缺省设置值是Any CPU,共有以下几种模式:

Any CPU: 表示所编译的EXE/DLL64位元平台(OS)就用64位元运行,32位元就用32位元运行;

x86: 表示所编译的EXE/DLL是以32位元模式,这除了可以在32位元OS上运行之外,也可以在64位元OS上运行,因为64位元OS提供了一种WOW64模式,可让32bit的程序也可在64位元OS上模拟32bit模式运行;

x64: 表示所编译的EXE/DLL只能在64位元模式运行,因此只能在64位元OS上运行

【图】VS2010 高级编译设置

com_error Traceback (most recent call last) File D:\anaconda3\Lib\site-packages\adodbapi\adodbapi.py:91, in connect(*args, **kwargs) 90 try: # connect to the database, using the connection information in kwargs ---> 91 co.connect(kwargs) 92 return co File D:\anaconda3\Lib\site-packages\adodbapi\adodbapi.py:266, in Connection.connect(self, kwargs, connection_maker) 265 try: --> 266 self.connector.Open() # Open the ADO connection 267 except api.Error: File <COMObject ADODB.Connection>:2, in Open(self, ConnectionString, UserID, Password, Options) File D:\anaconda3\Lib\site-packages\win32com\client\dynamic.py:355, in CDispatch._ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCLSID, *args) 354 def _ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCLSID, *args): --> 355 result = self._oleobj_.InvokeTypes( 356 *(dispid, LCID, wFlags, retType, argTypes) + args 357 ) 358 return self._get_good_object_(result, user, resultCLSID) com_error: (-2147352567, '发生意外。', (0, 'ADODB.Connection', '未找到提供程序。该程序可能未正确安装。', 'C:\\Windows\\HELP\\ADO270.CHM', 1240655, -2146824582), None) During handling of the above exception, another exception occurred: OperationalError Traceback (most recent call last) Cell In[3], line 6 4 import numpy as np 5 import matplotlib.pyplot as plt ----> 6 from adodbapi.examples.xls_read import sheet File D:\anaconda3\Lib\site-packages\adodbapi\examples\xls_read.py:25 21 filename = "xx.xls" 23 constr = "Provider=%s;Data Source=%s;%s" % (driver, filename, extended) ---> 25 conn = adodbapi.connect(constr) 27 try: # second command line argument will be worksheet name -- default to first worksheet 28 sheet = sys.argv[2] File D:\anaconda3\Lib\site-packages\adodbapi\adodbapi.py:95, in connect(*args, **kwargs) 93 except Exception as e: 94 message = 'Error opening connection to "%s"' % co.connection_string ---> 95 raise api.OperationalError(e, message) OperationalError: (com_error(-2147352567, '发生意外。', (0, 'ADODB.Connection', '未找到提供程序。该程序可能未正确安装。', 'C:\\Windows\\HELP\\ADO270.CHM', 1240655, -2146824582), None), 'Error opening connection to "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=-f;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1;""')
最新发布
08-13
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值