0

I am trying to build an inventory system for my discord bot, and I need to connect python to MS-Access using pyodbc. I want to be able to update, delete, and add values to the table.

I looked on datafish.com, specifically this website: https://datatofish.com/how-to-connect-python-to-ms-access-database-using-pyodbc/ but it does throw me the same error as issue one, and i've made sure that I am using both MS-Access and Python on 32 bit.

This is the code I used, pretty much straight from the website.

import pyodbc
conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\Khang Nguyen\Documents\Inventories.accdb')
cursor = conn.cursor()
cursor.execute('select *from TestTable')

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

When I use this code, it throws me this error:

Traceback (most recent call last):
  File "C:/Users/Khang Nguyen/AppData/Local/Programs/Python/Python38-32/Hey.py", line 3, in <module>
    conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\Khang Nguyen\Documents\Inventories.accdb')
pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

I expected it to print my table(A very simple table), but it throws me the above error message.

UPDATE: I have updated to Python 3.8, 32-bit, and upgraded my MS Access version. I am using the exact same code, and it throws me a completely different error:

Traceback (most recent call last):
  File "C:\Users\Khang Nguyen\AppData\Local\Programs\Python\Python38-32\Hey.py", line 3, in <module>
    conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\Khang Nguyen\Documents\Inventories.accdb')
pyodbc.Error: ('HY000', "[HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x79c Thread 0x2720 DBC 0x49763dc                                                              Jet'. (63) (SQLDriverConnect); [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x79c Thread 0x2720 DBC 0x49763dc                                                              Jet'. (63); [HY000] [Microsoft][ODBC Microsoft Access Driver] The database you are trying to open requires a newer version of Microsoft Access. (-1073); [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x79c Thread 0x2720 DBC 0x49763dc                                                              Jet'. (63); [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x79c Thread 0x2720 DBC 0x49763dc                                                              Jet'. (63); [HY000] [Microsoft][ODBC Microsoft Access Driver] The database you are trying to open requires a newer version of Microsoft Access. (-1073)")

The spacing is also extremely weird. I have made sure my MS Access is updated. Any solution? Maybe it's because MS Access Redistributable has been updated(I checked) but I don't know. I just know that the application I am building needs this code to function at all.

  • Does this answer your question? [Why am I getting "Data source name not found and no default driver specified" and how do I fix it?](https://stackoverflow.com/questions/58571740/why-am-i-getting-data-source-name-not-found-and-no-default-driver-specified-an) – Erik A Nov 08 '19 at 15:27
  • 1
    If you're using Office 2016/365 Click-to-run, you need a separate install of the Access Database Engine, as Office 365 doesn't expose ODBC drivers – Erik A Nov 08 '19 at 15:27

0 Answers0