Search code examples
odbcmdbtools

Can I make a DSN-less connection using pyodbc and mdbtools?


I've tried the following:

>>> import pyodbc

>>> cnxn = pyodbc.connect(Driver="MDB", database="SohabeD51.mdb")
pyodbc.Error: ('08001', '[08001] [unixODBC]Could not find DSN in
                connect string (1) (SQLDriverConnectW)')

Connecting to a database using a DSN entry works fine, but I'd like to supply a database in the code.


Solution

  • I know this is an old question, but actually (0.7.1) MDBTools DOES support DSN-less connections. The syntax for the connection string is something like

    DRIVER=Microsoft Access Driver (*.mdb);DBQ=/path/to/your/file.mdb;UID=;PWD=;
    

    You can download it from Github and compile it to ensure you are up to date:

    https://github.com/brianb/mdbtools