I am having trouble connecting to an MS Access database on our network drive using the python pyodbc library when the database is already opened by another process.
To reproduce the error, I first create a front end and back end Access Database with a table. I then open up the front end file in the MS Access Application so a .laccdb file is created for the backend. I then run the following code:
import pyodbc
pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=V:\Backend.accdb;')
V: is a shared network drive. Here is the error message I get:
pyodbc.Error: ('HY000', "[HY000] [Microsoft][ODBC Microsoft Access Driver] General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x85c Thread 0x2e0c DBC 0x92147c28 Jet'. (63) (SQLDriverConnect);
[HY000] [Microsoft][ODBC Microsoft Access Driver] Could not use '(unknown)'; file already in use.
I only get this error when the database is already open. There is no error when the script is the only process using the database.
Here is some other information:
I do not get this error when I repeat the test above on my local drive, so it seems to have something to do with the database being on the network drive.
I have the default open mode in MS Access to "Shared", so the database should not be opening in exclusive mode.
The error seems to have something to do with trying to connect via a Python script - for example, I can open the database front end / table using the MS Access Application, and then open up the back end file in MS Access Application simultaneously with no problem on the network drive.
I have read and write permission on the network directory. For example, I can create files and delete files in the network directory using Python scripts.
I have tried tweaking the ODBC Driver / Database Connection String, including opening in Read Only Mode, and Explicitly making sure exclusive mode is turned off. Neither of these options fix the problem.
My user has read access to the ODBC registry as suggested here.
System information:
- MS Access 2019 64-bit
- 64-bit MS Access ODBC Driver
- Python 3.9, using Anaconda environment / Anaconda prompt to run scripts
- pyodbc version 4.0.32
Any help would be greatly appreciated.