问题描述
在带有 pyodbc 的 Python 脚本中,我试图连接到我们网络上仍在使用的 Access 97 数据库,但我无法使连接(或连接字符串)正常工作.
In a Python script with pyodbc, I am trying to connect to a still used Access 97 database on our network but I have problems to get the connection (or the connection string) to work.
我不断收到以下错误:
pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnectW)')
这是我的连接字符串,由于上述错误而失败:
This is my connection string which fails with above mentioned error:
conn = pyodbc.connect('Driver={Microsoft Access Driver (.mdb)};Provider=Microsoft.Jet.OLEDB.4.0;Password=mypassword;User ID=myusername;dbq=\\fileserver\\conta\\locationdir\\mydatabase_be.mdb;Persist Security Info=True;Jet OLEDB:System database=\\FILESERVER\\backend\\mdw\\system.mdw')
如您所见,此连接需要使用系统数据库(工作组 - mdw).数据库位于网络存储中.
As you can see, this connection requires to use a System database (workgroup - mdw). The database is on a network-storage.
我使用的是 Python 2.7.
I am using Python 2.7.
有人可以帮忙吗?
在连接字符串中,反斜杠应该是双反斜杠.似乎只显示了一个反斜杠.
in the connection-string, the backslashes should be double backslashes. It seems like only a single backslash is shown.
推荐答案
好的,我已经整理好了.我的解决方案基于以下代码段(只是语法正确的问题):
OK, I got it sorted. My solution was based on the following snippet (was just a matter of getting the syntax right):
strConnection = (r"Driver={Microsoft Access Driver (*.mdb)};"
r"Dbq=C:\\VC Projects\\ADO\\Samples\\AdoTest\\dbTestSecurity.mdb;"
r"SystemDB=C:\\Program Files\\Microsoft Office\\Office\\SYSTEM.mdw;"
r"Uid=Carlos Antollini;Pwd=carlos")
conn = pyodbc.connect(strConnection)
#your code
在此网页
希望这对其他人有用.
这篇关于如何使用 pyodbc 连接到 MS Access 97(使用工作组 mdw)数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!