无法使用64位Python 3.6连接到64位MsAccess数据库.ODBC驱动程序错误 [英] cannot connect to 64bit MsAccess database with 64bit Python 3.6.ODBC Driver Error

查看:501
本文介绍了无法使用64位Python 3.6连接到64位MsAccess数据库.ODBC驱动程序错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在新计算机上安装了64位Microsoft Office,还安装了64位python 3.6.

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

我正在尝试使用python脚本连接到Access数据库,但是我不断收到以下错误消息,这表明我拥有32位ODBC驱动程序而不是64位驱动程序?

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?

关于如何无需安装32位MS Office和32位Python进行连接的任何想法?

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驱动程序管理器]数据源名称未找到且未指定默认驱动程序(0)(SQLDriverConnect)")

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

这是我的代码:

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")

推荐答案

我个人还没有处理过64位MS Office应用程序或驱动程序,但是

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).

为此,即使 Access Database Engine 2010可重新分发也有64位版本.

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

您还可以使用ODBC数据源管理器来创建和管理DSN(数据源名称).对于32位和64位程序,有单独的管理员程序.在我的Windows 10计算机上,快捷方式位于"Windows管理工具"下,并标记为"ODBC数据源(32位)"和"ODBC数据源(64位)".

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)'.

通过定义DNS,可以指定用于打开数据库的驱动程序.但是您还必须能够在连接参数中引用DNS,很遗憾,我不熟悉如何在python程序中执行此操作.我至少希望这能暗示要开始.

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.

这篇关于无法使用64位Python 3.6连接到64位MsAccess数据库.ODBC驱动程序错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆