I've been beating my head against this for a few days now. I'm trying to use pyodbc to connect to a Microsoft Access DB, and I can't seem to get the connection string right or something. This is what I'm using:
cnxn = pyodbc.connect(r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Path\to\file.accdb')
I keep getting the error:
Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnectW)')
Even though when I run dataSources()
I see:
{'MS Access Database': 'Microsoft Access Driver (*.mdb, *.accdb)', 'dBASE Files': 'Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)', 'Excel Files': 'Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)'}
Is there something I'm severely missing here?
This is a 64-bitness problem. I solved it by using 32-bits python and pyodbc.
Try adding Provider=MSDASQL
. It's deprecated but it seems to work OK:
cnxn = pyodbc.connect(r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};
DBQ=C:\Path\to\file.accdb; Provider=MSDASQL;')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With