简体   繁体   中英

Pyodbc IM002 database connection

I have successfully connected to this database many times before, but just now I have encountered this error:

pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

This is my code:

pathofprog = os.path.dirname(__file__) #Locates the path of the program
dblocation = os.path.join(pathofprog, "Database.accdb") #Locates the database at this path
db = pyodbc.connect('Driver={Microsoft Access Driver (*.mdb, *.accdb)}; Dbq=%s;'%dblocation) #Connects to the database
dbcursor = db.cursor() #Creates the database cursor

Any help would be much appreciated

I follow Gord Thompson's advice in comments to question and printed the list of drivers on my system and resolved it by changing the driver from:

DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}

to

DRIVER={Microsoft Access Driver (*.mdb)

Hope that help, Warren

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM