I have read a hundred pages online as to how to connect to legacy MS Access databases to Python, but everything seems to be dated. I am using Python 3.7 64-bit, with SQLAlchemy and PyODBC, but SQLAlchemy doesn't support MS Access anymore, and I can't get any code to work. Has anyone got a modern version of Python to connect to Access lately? Here's my code that doesn't work.
import pyodbc
connStr = (
r"DRIVER={Microsoft Access Driver (*.accdb)}; DBQ=E:\db\Records.accdb; Uid=Admin; Pwd=;"
)
conn = pyodbc.connect(connStr)
cursor = conn.cursor()
cursor.execute('select * from Students')
for row in cursor.fetchall():
print(row)
The Error:
Traceback (most recent call last): File "G:/Projects/AccessTest/accessdb.py", line 7, in conn = pyodbc.connect(connStr) pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
Microsoft Access Driver (*.accdb). Check the list returned bypyodbc.drivers()to see ifMicrosoft Access Driver (*.mdb, *.accdb)is available to your Python app, and if not then install it. - Gord Thompson