我在 Windows 7、Python 2.7 和 Microsoft Access 2013 上运行。
当我尝试运行时:
import pyodbc
conn_string = '''
DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};
UID=admin;
UserCommitSync=Yes;
Threads=3;
SafeTransactions=0;
PageTimeout=5;
MaxScanRows=8;
MaxBufferSize=2048;
FIL=MS Access;
DriverId=25;
DefaultDir=C:\Users\jseinfeld;
DBQ=C:\Users\jseinfeld\Desktop\Databasetest1.accdb;
'''
connection = pyodbc.connect(conn_string)
我收到以下错误消息:
Error: ('HY000', "[HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x29dc Thread 0x113c DBC 0x8a3ed48
Jet'. (63) (SQLDriverConnect); [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x29dc Thread 0x113c DBC 0x8a3ed48
Jet'. (63); [HY000] [Microsoft][ODBC Microsoft Access Driver] Not a valid file name. (-1044); [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x29dc Thread 0x113c DBC 0x8a3ed48
Jet'. (63); [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x29dc Thread 0x113c DBC 0x8a3ed48
Jet'. (63); [HY000] [Microsoft][ODBC Microsoft Access Driver] Not a valid file name. (-1044)")
我知道有很多关于 Pyodbc 和 MS Access 的问题。我已经执行了以下操作:
1) 确保我有 64 位 Python 和 64 位 MS Access
2) 允许帐户 Access HKEY_LOCAL_MACHINE\SOFTWARE\ODBC 注册表项
https://support.microsoft.com/en-us/kb/295297
Error in opening an Access database in python
"General error Unable to open registry key Temporary (volatile) ..." from Access ODBC
3) 试图确保我有一个有效的连接字符串 https://stackoverflow.com/questions/6469545/python-connecting-to-a-database-with-pyodbc-not-working#=
4) 当我尝试运行这段代码时,Access 数据库没有打开。我已重新启动计算机,但仍收到此错误。
如果我可以尝试任何其他操作,请告诉我。
最佳答案
从一个只有 DRIVER
和 DBQ
属性且没有嵌入式换行符的简单连接字符串开始......
conn_string = r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\jseinfeld\Desktop\Databasetest1.accdb;'
一旦您获得最简单的连接字符串,您就可以根据需要添加和测试其他连接属性。
关于python - Pyodbc 错误 - Python 到 MS Access,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36180703/