【发布时间】:2016-03-23 14:17:14
【问题描述】:
我在 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) 授予帐户访问 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 数据库未打开。我已重新启动计算机,但仍然收到此错误。
如果我可以尝试任何其他操作,请告诉我。
【问题讨论】:
-
您构建连接字符串的方式意味着它包含嵌入的换行符。你试过没有换行吗? ...从原始字符串开始,如下所示:
conn_string = r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\jseinfeld\Desktop\Databasetest1.accdb;' -
很好的标注,但是我已经尝试过了
-
那些“不是有效的文件名”。条目表明它可能是文件路径中的拼写错误或权限问题。您是否尝试过将文件复制到“C:\Users\Public\...”之类的地方(并仔细检查文件名)?
-
另外,我从未在 Access 连接字符串中看到
Threads=。建议您将 Gord 的建议与简化的连接字符串结合起来......仅从Driver和DBQ属性开始。 -
@HansUp 我收回我的最后评论。我试过
conn_string = 'rDRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\jseinfeld\Desktop\Databasetest1.accdb;'但不是conn_string = r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\jseinfeld\Desktop\Databasetest1.accdb;'你在这里的第一条评论解决了我的问题。您可以将其发布为答案,以便我给予您信任吗?
标签: python ms-access odbc pyodbc