pyodbc.InterfaceError :(“ IM002”,“ [IM002] [Microsoft] [ODBC驱动程序管理器]数据源名称未找到且未指定默认驱动程序(0)(SQLDriverConnect)”)
这是我的代码:
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位
Office 365
安装了Microsoft Access Engine 2010 64位
运行这段代码:
>>> 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)']
给我错误
pyodbc.InterfaceError :(“ IM002”,“ [IM002] [Microsoft] [ODBC驱动程序管理器]数据源名称未找到且未指定默认驱动程序(0)(SQLDriverConnect)”)
我还想念什么?还有其他连接方式吗?
答案 0 :(得分:0)
这里不需要大括号:
db = pyodbc.connect('Driver=Microsoft Access Driver (*.mdb, *.accdb); Dbq=%s;'%dblocation)