简体   繁体   English

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

[英]cannot connect to 64bit MsAccess database with 64bit Python 3.6.ODBC Driver Error

I have just installed 64-bit microsoft office on a new computer and also installed 64bit python 3.6.我刚刚在一台新电脑上安装了 64 位 microsoft office,还安装了 64 位 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?我正在尝试使用我的 python 脚本连接到访问数据库,但是我不断收到以下错误,这表明我使用的是 32 位 ODBC 驱动程序而不是 64 位驱动程序?

Any ideas on how to connect without having to install 32bit MS Office and 32bit Python?关于如何在无需安装 32 位 MS Office 和 32 位 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)') cnxn = pyodbc.connect(connstr) pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] 未找到数据源名称且未指定默认驱动程序 (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).我个人没有处理过 64 位 MS Office 应用程序或驱动程序,但是Access Database Engine 2016 Redistributable包含一个 64 位版本,包括 ODBC 驱动程序(我认为)。

For that matter, even the Access Database Engine 2010 Redistributable also has a 64-bit version.就此而言,即使是Access Database Engine 2010 Redistributable也有 64 位版本。

You can also use ODBC Data Source Administrator to create and manage DSN (Data Source Name).您还可以使用 ODBC 数据源管理器来创建和管理 DSN(数据源名称)。 There are separate administrator programs for 32-bit and 64-bit programs. 32 位和 64 位程序有单独的管理员程序。 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)'.在我的 Windows 10 机器上,快捷方式位于“Windows 管理工具”下,并标有“ODBC 数据源(32 位)”和“ODBC 数据源(64 位)”。

By defining a DNS, you can specify which driver to use for opening the database.通过定义 DNS,您可以指定使用哪个驱动程序打开数据库。 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.但是您还必须能够在您的连接参数中引用 DNS,遗憾的是我不熟悉如何在您的 python 程序中执行此操作。 I at least hope this gives a hint on were to start.我至少希望这给出了一个开始的暗示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM