0

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.

Robert
  • 7,394
  • 40
  • 45
  • 64
  • Does this answer your question? [What do I need to read Microsoft Access databases using Python?](https://stackoverflow.com/questions/853370/what-do-i-need-to-read-microsoft-access-databases-using-python) – itprorh66 Mar 25 '22 at 14:00
  • Please show your actual code - your description doesn't match your code. ALso did you install mdbtools and odbc-mdbtools – dbmitch Mar 28 '22 at 22:18

1 Answers1

0

visit https://www.microsoft.com/en-us/download/details.aspx?id=54920 to download Microsoft Access Database Engine 2016 Redistributable

Select "ODBC Data Sources (64-bit) "

Then go to Control Panel> System and Security> Administrative Tools( or simply search "Administrative Tools" in windows), and make sure the drivers are installed.

The following code should show your driver:

*import pyodbc

msa_drivers = [x for x in pyodbc.drivers() if 'ACCESS' in x.upper()] print(f'MS-Access Drivers : {msa_drivers}')*

PeterPan
  • 11
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 11 '23 at 00:32