我正在尝试从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)')
答案 0 :(得分:1)
import pypyodbc
不属于ODBC连接字符串。此外,连接字符串可能会被换行符和空格混淆。你应该有更好的运气:
connStr = (
r"Driver={Microsoft Access Driver (*.mdb, *.accdb)};"
r"DBQ=C:\Users\haesh\Desktop\Comp Sci CC\Database1.accdb;"
)