I am trying to connect Python to MS Access Database using pyodbc but every time I get the following error:
pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
And this what I have written to connect python to MS Access:
import pyodbc
conn = pyodbc.connect(r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:\PILOT_DATA.accdb;')
cursor = conn.cursor()
cursor.execute('select * from p_inventor')
for row in cursor.fetchall():
print (row)
According to the error, it doesn't find the Data source name and so I changed the 'DRIVER' to 'DSN'
import pyodbc
conn = pyodbc.connect(r'DSN={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:\PILOT_DATA.accdb;')
cursor = conn.cursor()
cursor.execute('select * from p_inventor')
for row in cursor.fetchall():
print (row)
But it doesn't help. I get the following error:
pyodbc.Error: ('IM010', '[IM010] [Microsoft][ODBC Driver Manager] Data source name too long (0) (SQLDriverConnect)')
Other workaround I have tried is to use both python 32 and 64 bit
Here goes the version details:
Would be really helpful to know what else I can do to connect Python to ACCESS database. Thanks in Advance!
I have solved this issue by installing the Access Database Engine. In order to do that, I had to unistall the office365 program-> install access database engine-> re-install office365. And then the code runs perfectly!