python连接access2016_无法使用64位Python 3.6连接到64位MsAccess数据库。ODBC驱动程序错误...

I have just installed 64-bit microsoft office on a new computer and also installed 64bit python 3.6.

I'm trying to connect to an access database with my python script, however I keep getting the following error which suggests I have the 32bit ODBC driver instead of the 64bit driver?

Any ideas on how to connect without having to install 32bit MS Office and 32bit Python?

This is the error message I get:

cnxn = pyodbc.connect(connstr)

pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

Here's my code:

import pyodbc

connStr = (

r"DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};"

r"DBQ=C:\Documents\Test.accdb;"

)

cnxn = pyodbc.connect(connStr)

cursor = cnxn.cursor()

cursor.execute("SELECT * FROM Test")

解决方案

I personally have not dealt with 64-bit MS Office apps or drivers, however the Access Database Engine 2016 Redistributable contains a 64-bit version including ODBC drivers (I think).

For that matter, even the Access Database Engine 2010 Redistributable also has a 64-bit version.

You can also use ODBC Data Source Administrator to create and manage DSN (Data Source Name). There are separate administrator programs for 32-bit and 64-bit programs. On my Windows 10 machine, the shortcuts are under 'Windows Administrative Tools' and are labeled 'ODBC Data Source (32-bit)' and 'ODBC Data Source (64-bit)'.

By defining a DNS, you can specify which driver to use for opening the database. But you must also be able to refer to the DNS in your connection parameters, regrettably I am not familiar with how to do that in your python program. I at least hope this gives a hint on were to start.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值