Python从MS Access导入:"无效的连接字符串属性"

时间:2016-06-22 18:39:39

标签: python ms-access python-3.3

我正在尝试从MS Access数据库导入数据

import pyodbc

connStr = """

import pypyodbc
Driver={Microsoft Access Driver (*.mdb, *.accdb)}
DBQ = C:\\Users\\haesh\\Desktop\\Comp Sci CC\\Database1.accdb;

"""
cnxn = pyodbc.connect(connStr)

但是我收到此错误

Traceback (most recent call last):
File "C:\Users\haesh\Desktop\Comp Sci CC\qwerty.py", line 10, in <module>
cnxn = pyodbc.connect(connStr)
pyodbc.Error: ('01S00', '[01S00] [Microsoft][ODBC Driver Manager] Invalid connection string attribute (0) (SQLDriverConnect)')

1 个答案:

答案 0 :(得分:1)

import pypyodbc不属于ODBC连接字符串。此外,连接字符串可能会被换行符和空格混淆。你应该有更好的运气:

connStr = (
    r"Driver={Microsoft Access Driver (*.mdb, *.accdb)};"
    r"DBQ=C:\Users\haesh\Desktop\Comp Sci CC\Database1.accdb;"
    )