How to connect to MS Access 97 (with workgroup mdw

2019-09-07 04:04发布

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.

I keep getting the following error:

   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')

As you can see, this connection requires to use a System database (workgroup - mdw). The database is on a network-storage.

I am using Python 2.7.

Can anyone help?

EDIT: in the connection-string, the backslashes should be double backslashes. It seems like only a single backslash is shown.

1条回答
Animai°情兽
2楼-- · 2019-09-07 04:42

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

Solution found in this web-page

Hope this may be useful for someone else.

查看更多
登录 后发表回答