BeeGee
BeeGee

Reputation: 875

Pyodbc Error - Python to MS Access

I am running on Windows 7, Python 2.7 and Microsoft Access 2013.

When I try running:

import pyodbc
conn_string = '''
DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};
UID=admin;
UserCommitSync=Yes;
Threads=3;
SafeTransactions=0;
PageTimeout=5;
MaxScanRows=8;
MaxBufferSize=2048;
FIL=MS Access;
DriverId=25;
DefaultDir=C:\Users\jseinfeld;
DBQ=C:\Users\jseinfeld\Desktop\Databasetest1.accdb;
'''
connection = pyodbc.connect(conn_string)

I receive the following error message:

Error: ('HY000', "[HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x29dc Thread 0x113c DBC 0x8a3ed48    

Jet'. (63) (SQLDriverConnect); [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x29dc Thread 0x113c DBC 0x8a3ed48

Jet'. (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 0x29dc Thread 0x113c DBC 0x8a3ed48 

Jet'. (63); [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x29dc Thread 0x113c DBC 0x8a3ed48

Jet'. (63); [HY000] [Microsoft][ODBC Microsoft Access Driver] Not a valid file name. (-1044)")

I realize there are many questions regarding Pyodbc and MS Access. I have already executed the following:

1) Ensured I have 64 bit Python and 64 bit MS Access

2) Given permission to the account access to the HKEY_LOCAL_MACHINE\SOFTWARE\ODBC registry key

https://support.microsoft.com/en-us/kb/295297

Error in opening an Access database in python

"General error Unable to open registry key Temporary (volatile) ..." from Access ODBC

3) Tried to ensure I have a valid connection string https://stackoverflow.com/questions/6469545/python-connecting-to-a-database-with-pyodbc-not-working#=

4) The Access database is not open when I try running this code. I have re-booted my computer and am still receiving this error.

Please let me know if there is any other action I can try.

Upvotes: 4

Views: 13300

Answers (3)

Mohammed GADIRI
Mohammed GADIRI

Reputation: 1

if you use just *.mdb you can build the connection like this: to avoid the error ODBC Driver not found.

db_main = f"C:\Users\jseinfeld\Desktop\Databasetest1.mdb"

conn_string = r"DRIVER={Microsoft Access Driver (*.mdb)};" \
   f"DBQ={db_main}"

Upvotes: 0

Gord Thompson
Gord Thompson

Reputation: 123549

Additional to HansUp's answer, I use the following technique to build connection strings without embedded line breaks that are still easy to read by us humans:

conn_string = (
    r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
    r'DBQ=C:\Users\jseinfeld\Desktop\Databasetest1.accdb;')

Upvotes: 4

HansUp
HansUp

Reputation: 97101

Start with a simple connection string with only the DRIVER and DBQ attributes and no embedded line breaks ...

conn_string = r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\jseinfeld\Desktop\Databasetest1.accdb;'

Once you get the simplest connection string working, you can add and test other connection attributes as needed.

Upvotes: 6

Related Questions