Home:ALL Converter>Opening a Microsoft Access database file(*mdb) using Python

Opening a Microsoft Access database file(*mdb) using Python

Ask Time:2022-03-25T20:25:52         Author:brian odero

Json Formatter

I've got an Access database located in m local files, which contains a .mdb (MS Access Database) file, with multiple rows and columns.

I want to work with that file in Python, via Google Colab (preferably), but can't find a way to properly open and read the file.

I installed pyodbc, imported it via import pyodbc as pyo, and added a connection string:

import pyodbc

conn = pyodbc.connect(r"Driver={Microsoft Access Driver (\*.mdb, \*.accdb)};DBQ=C:\\Users\\odero\\Documents\\dec\\Multi\\Database1.mdb;")
cursor = conn.cursor()
cursor.execute('select \* from OIL')

for row in cursor.fetchall():
    print (row)

with the .mdb file being the original file of the dataset I am using, which contains the .mdb file.

However, when trying to connect it to the pyo by stating

cnn = pyo.connect(cnnstr)

I get:

Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'Microsoft Access Driver (*.mdb, *.accdb)' : file not found (0) (SQLDriverConnect)").

That's pretty much what I could do overall, I just don't know where to look/what to do.

Any help will be much appreciated.

Author:brian odero,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/71616986/opening-a-microsoft-access-database-filemdb-using-python
yy