For some reason I have have a hard time with my access driver here. I use the driver to connect to my access database. The error I am getting is:
2022-01-24 08:46:07 AM | ERROR | Zero Dollar Fee Aging Report | Error reading database.
2022-01-24 08:46:07 AM | ERROR | Zero Dollar Fee Aging Report | (pyodbc.Error) ('HY000', "[HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x3cdc Thread 0x4a3c DBC 0xe8b4534 Jet'. (63) (SQLDriverConnect); [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x3cdc Thread 0x4a3c DBC 0xe8b4534 Jet'. (63); [HY000] [Microsoft][ODBC Microsoft Access Driver] Could not use '(unknown)'; file already in use. (-1024)")
(Background on this error at: http://sqlalche.me/e/13/dbapi)
Here is the block code I'm using:
def access_engine(db_path):
"""A function to generate a sqlalchemy engine for an Access database. This
function requires the user to have a compatible Access driver installed
(usually a 32-bit driver with a 32-bit Python installation).
Args:
db_path (str): The relative or absolute path to the database, ending in
*.mdb or *.accdb.
Returns:
sqlalchemy.engine.base.Engine: An engine to connect to the database.
"""
# TODO: Add a check for driver installation
connection_string = str(
r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};'
r'DBQ=%s' % db_path)
connection_url = "access+pyodbc:///?odbc_connect={}".format(
urllib.parse.quote_plus(connection_string))
return _create_engine(connection_url)
def read_database(logger, db_path, table):
logger = dmttools.util.DefaultLogger(logger)
logger.info('Reading existing database...')
sq = "SELECT * FROM `{}`"
try:
engine = dmttools.database.access_engine(db_path)
df = pd.read_sql_query(sq.format(table), engine)
logger.info('Read.')
return df
except Exception as e:
logger.error('Error reading database.')
logger.error(e)
raise e
finally:
engine.dispose()
access_zeroDollar = read_database('Zero Dollar Fee Aging Report', dmttools.paths.payments_db, 'Site Visit Fees-Zero Amount')
Is anyone else encountering this?