How to connect to MS Access 97 (with workgroup mdw) database using pyodbc

我是研究僧i 提交于 2019-12-12 03:24:39

问题


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:


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.



来源:https://stackoverflow.com/questions/31388811/how-to-connect-to-ms-access-97-with-workgroup-mdw-database-using-pyodbc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!