python - 使用 pyodbc 连接到数据库 - 不起作用
我正在尝试使用以下连接字符串连接到 Access 2007 数据库。
conn = pyodbc.connect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=<C:\Users\JSeinfeld\Desktop\Backup databases\Database_6.7.accdb>;")
我收到此错误:
回溯(最近一次调用最后一次):
文件“”,第 1 行,位于 conn = pyodbc.connect("驱动程序={Microsoft 访问驱动程序(*.mdb、 *.accdb)};DBQ=;")错误:('HY000',“[HY000] [微软][ODBC Microsoft Access 驱动程序]一般错误无法打开 注册表项临时(易失)Ace 进程 0x167c 线程 0x1568 的 DSN DBC 0x1c67a5c
喷气机”。 (63) (SQLDriverConnectW); [HY000] [微软][ODBC 微软 访问驱动程序]一般错误无法 打开注册表项临时(易失) 进程 0x167c 线程的 Ace DSN 0x1568 DBC 0x1c67a5c
喷气机”。 (63); [HY000] [微软][ODBC Microsoft Access 驱动程序] 无效 文件名。 (-1044); [HY000] [微软][ODBC Microsoft Access 驱动程序]一般错误无法打开 注册表项临时(易失)Ace 进程 0x167c 线程 0x1568 的 DSN DBC 0x1c67a5c
喷气机”。 (63); [HY000] [微软][ODBC Microsoft Access 驱动程序]一般错误 临时无法打开注册表项 (易失性)进程 0x167c 的 Ace DSN 线程 0x1568 DBC 0x1c67a5c
喷气机”。 (63); [HY000] [微软][ODBC Microsoft Access 驱动程序] 无效 文件名。 (-1044)")
还有一个类似的问题,但是有一个我没有的 32/64 位兼容性问题。这个问题似乎没有一个好的答案,但希望有人可以帮助我连接到我的数据库,因为我不知道使用 python 查询或写入数据到 Access 2007 的任何其他方法
。
I am trying to connect to an Access 2007 database with the following connection string.
conn = pyodbc.connect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=<C:\Users\JSeinfeld\Desktop\Backup databases\Database_6.7.accdb>;")
I get this error:
Traceback (most recent call last):
File "", line 1, inconn = pyodbc.connect("Driver={Microsoft
Access Driver (*.mdb,
*.accdb)};DBQ=;")Error: ('HY000', "[HY000]
[Microsoft][ODBC Microsoft Access
Driver]General error Unable to open
registry key Temporary (volatile) Ace
DSN for process 0x167c Thread 0x1568
DBC 0x1c67a5cJet'. (63) (SQLDriverConnectW);
[HY000] [Microsoft][ODBC Microsoft
Access Driver]General error Unable to
open registry key Temporary (volatile)
Ace DSN for process 0x167c Thread
0x1568 DBC 0x1c67a5cJet'. (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 0x167c Thread 0x1568
DBC 0x1c67a5cJet'. (63); [HY000] [Microsoft][ODBC
Microsoft Access Driver]General error
Unable to open registry key Temporary
(volatile) Ace DSN for process 0x167c
Thread 0x1568 DBC 0x1c67a5cJet'. (63); [HY000] [Microsoft][ODBC
Microsoft Access Driver] Not a valid
file name. (-1044)")
There is another question like this on SO, but there was a 32/64bit compatibility issue which I do not have. There doesn't seem to be a good answer for this question, but hopefully someone can help me connect to my database because I don't know of any other way to query or write data to Access 2007 with python.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
遇到了同样的问题 - 这是转义访问数据库位置中使用的反斜杠的简单情况
>>> conn = pyodbc.connect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\\access\\site_be.accdb;")
的工作方式与
>>> conn = pyodbc.connect("Driver={Microsoft Access 驱动程序 (*.mdb, *.accdb)};DBQ=C:\access\site_be.accdb;")
给了我错误
<代码>喷气机'。 (63); [HY000] [Microsoft][ODBC Microsoft Access 驱动程序] 不是有效的文件名。 (-1044)")
希望
有帮助..
Had the same issue - it was a simple case of escaping the backslash used in the location of the access db
>>> conn = pyodbc.connect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\\access\\site_be.accdb;")
worked as whereas
>>> conn = pyodbc.connect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\access\site_be.accdb;")
was giving me the error
Jet'. (63); [HY000] [Microsoft][ODBC Microsoft Access Driver] Not a valid file name. (-1044)")
Hope that helped..
尝试去掉文件名中的括号。
Try taking the brackets out of the file name.
您的文件夹中有 *.ldb 文件吗?
我有非常相似的错误消息,但我的错误消息还包括“文件已在使用中”。就我而言,我最终意识到数据库上有一个锁(.mdb 旁边的 .ldb 文件)。我有一个一直在使用数据库的服务正在运行——我想是时候切换到多用户数据库引擎了。
作为实验,我制作了数据库的副本,并且 pyodbc 连接到该副本效果很好。这显然不是一个长期的解决方案,但至少现在我知道问题出在哪里。
Is there an *.ldb file in your folder?
I had very similar error messages, but mine also included "file already in use." In my case, I finally realized that there was a lock on the database (an .ldb file next to the .mdb). I have a service running that uses the database all the time -- I guess it's time to switch to a multi-user database engine.
As an experiment, I made a copy of the database, and pyodbc connected to the copy just fine. This obviously isn't a long-term solution, but at least now I know what the problem was.
法比卢斯说得对。
反斜杠字符表示下一个字符在字符串中具有特殊含义。所以破译双反斜杠...第一个反斜杠告诉Python准备特殊字符串字符,第二个反斜杠是特殊字符串字符(在本例中是反斜杠)
Fabiolus got it right.
The backslash character means that the next character has special meaning in a string. So deciphering the double backslash... The first backslash tells python to prepare for a special string character, the second backslash is the special string character (which in this case is a backslash)