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.