3

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.

Community
  • 1
  • 1
BeeGee
  • 815
  • 2
  • 17
  • 33
  • 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;'` – HansUp Mar 23 '16 at 14:24
  • good call-out but yes I have tried exactly that – BeeGee Mar 23 '16 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)? – Gord Thompson Mar 23 '16 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. – HansUp Mar 23 '16 at 14:32
  • @GordThompson I am assured the file path name is correct. I put the database on my desktop. I agree that there might be a permissions issue because this is not a personal computer. But I do not know how to check for that. I have followed a previous answer of yours: http://stackoverflow.com/questions/11473737/error-in-opening-an-access-database-in-python – BeeGee Mar 23 '16 at 14:35
  • @HansUp I have tried many different connection strings including the one from your comment: `conn_string = r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\jseinfeld\Desktop\Databasetest1.accdb;` – BeeGee Mar 23 '16 at 14:35
  • 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? – BeeGee Mar 23 '16 at 14:42

2 Answers2

5

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.

HansUp
  • 95,961
  • 11
  • 77
  • 135
3

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;')
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418