0
votes

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.mdb") #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

Python 3.7 64-bit
Office 365
Microsoft Access Engine 2010 64-bit installed

on running this piece of code:

>>> pyodbc.drivers()
['SQL Server', 'SQL Server Native Client 11.0', 'ODBC Driver 13 for SQL Server', 'SQL Server Native Client RDA 11.0', 'Microsoft Access Driver (*.mdb, *.accdb)', 'Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)', 'Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)', 'Microsoft Access Text Driver (*.txt, *.csv)']

Gives me error

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

What else am I missing? is there any other way to connect?

1

1 Answers

0
votes

You don't need braces here:

db = pyodbc.connect('Driver=Microsoft Access Driver (*.mdb, *.accdb); Dbq=%s;'%dblocation)