【问题标题】:Cannot connect to Access database with python-64Bit无法使用 python-64Bit 连接到 Access 数据库
【发布时间】:2019-09-17 08:14:13
【问题描述】:

pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (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 Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

我还缺少什么?有没有其他的连接方式?

【问题讨论】:

    标签: python-3.x ms-access


    【解决方案1】:

    这里不需要大括号:

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

    【讨论】:

      猜你喜欢
      • 2011-08-03
      • 2013-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多