无法使用 pyodbc 连接到 Access DB
几天来我一直在为此绞尽脑汁。我正在尝试使用 pyodbc 连接到 Microsoft Access DB,但我似乎无法正确获取连接字符串或其他内容。这就是我正在使用的:
cnxn = pyodbc.connect(r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Path\to\file.accdb')
我不断收到错误:
错误:('IM002', '[IM002] [Microsoft][ODBC Driver Manager] 未找到数据源名称且未指定默认驱动程序 (0) (SQLDriverConnectW)')
即使当我运行 dataSources()
时,我看到:
{'MS Access Database': 'Microsoft Access Driver (*.mdb, *.accdb)', 'dBASE Files ': 'Microsoft Access dBASE 驱动程序(*.dbf、*.ndx、*.mdx)'、'Excel 文件': 'Microsoft Excel 驱动程序(*.xls、*.xlsx、*.xlsm、*.xlsb)'}
有什么我严重想念的东西吗?
I've been beating my head against this for a few days now. I'm trying to use pyodbc to connect to a Microsoft Access DB, and I can't seem to get the connection string right or something. This is what I'm using:
cnxn = pyodbc.connect(r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Path\to\file.accdb')
I keep getting the error:
Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnectW)')
Even though when I run dataSources()
I see:
{'MS Access Database': 'Microsoft Access Driver (*.mdb, *.accdb)', 'dBASE Files': 'Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)', 'Excel Files': 'Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)'}
Is there something I'm severely missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个 64 位问题。我通过使用 32 位 python 和 pyodbc 解决了这个问题。
This is a 64-bitness problem. I solved it by using 32-bits python and pyodbc.
尝试添加
Provider=MSDASQL
。它已已弃用,但似乎工作正常:Try adding
Provider=MSDASQL
. It's deprecated but it seems to work OK: