1
votes

I am using Python 2.7.8 32-bit to call MS Access 2007.

Below is the code I use:

import sys
import pypyodbc
import os
import pyodbc

conn = pyodbc.connect(r"DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; Dbq=D:\Access\Geocoding.accdb;")
cnxn   = pyodbc.connect(conn)

I get the error message:

Traceback (most recent call last): File "D:\Access\get_Access.py", line 13, in conn = pyodbc.connect(r"DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; Dbq=D:\Access\Geocoding.accdb;") Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

I searched online for a while and couldn't find anything wrong with the code.

2
if I only ran the first line of code, it gives the same error message.Jen
I tried the solution in Connecting to MS Access 2007 (.accdb) database using pyodbc , it doesn't solve the problem.Jen

2 Answers

0
votes

I solved the problem. The Access database is created in Access 2013. I am try to use Python to connect it in Access 2007, that is the problem.

I created a Access 2007 database and copy all the data into it. Python can connect to it without problem.

-2
votes

Try to use double slash instead of slash in your db path. And write DBQ all uppercase

Your path should be something like this:

DBQ=D:\\Access\\Geocoding.accdb;