I am trying to connect to an MS Access (2013, 64 bits) database I created. However I am getting the following error:
('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
I know the question has been asked before and the solution usually seems to have to do with string formatting, but I could not make my script work.
Here is my code:
import pyodbc
con_string = 'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Temp\Database1.accdb;'
con_string2 = 'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;PageTimeout=5;MaxScanRows=8;MaxBufferSize=2048;FIL={MS Access};DriverId=25;DefaultDir=C:/temp;DBQ=C:/temp/Database1.accdb;'
try:
mdb_con = pyodbc.connect(con_string2)
except pyodbc.Error as error:
print error, "Can't connect"
Note that I created two connection strings, the first one based on what I saw online, and the second one using a DSN file I created using the Access database.