4

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.

7
  • The way you build the connection string means that it includes embedded line breaks. Have you tried it without line breaks? ... starting from a raw string something like this: conn_string = r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\jseinfeld\Desktop\Databasetest1.accdb;' Commented Mar 23, 2016 at 14:24
  • good call-out but yes I have tried exactly that Commented Mar 23, 2016 at 14:26
  • 1
    Those "Not a valid file name." entries suggest that it might be a typo in the file path or perhaps a permissions issue. Have you tried copying the file to someplace like "C:\Users\Public\..." (and double-checking the file name)? Commented Mar 23, 2016 at 14:27
  • Also, I've never seen Threads= in an Access connection string. Suggest you combine Gord's suggestion with a simplified connection string ... starting with just the Driver and DBQ properties. Commented Mar 23, 2016 at 14:32
  • 1
    @HansUp I take back my last comment. I have tried conn_string = 'rDRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\jseinfeld\Desktop\Databasetest1.accdb;' but not conn_string = r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\jseinfeld\Desktop\Databasetest1.accdb;' Your first comment here solved my issue. Can you post it as an answer so I can give you credit? Commented Mar 23, 2016 at 14:42

3 Answers 3

6

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.

Sign up to request clarification or add additional context in comments.

Comments

4

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

Comments

0

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}"

1 Comment

Note that this will only work for apps running under 32-bit Python (on Windows).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.