可能重复:
与 Access 数据库的连接错误
我在连接到 Northwind.accdb 数据库的 python 上编写了程序
import pyodbc
#import kinterbasdb
import firebirdsql
import os, sys
import json,sqlite3,sql
sys.version_info
s1='''
create table CLIENTS
(
ID INTEGER NOT NULL,
COMPANY VARCHAR(50),
"LAST NAME" VARCHAR(50),
"FIRST NAME" VARCHAR(50),
"E-MAIL ADDRESS" VARCHAR(50),
"JOB TITLE" VARCHAR(50),
"BUSINESS PHONE" VARCHAR(25),
"HOME PHONE" VARCHAR(25),
"MOBILE PHONE" VARCHAR(25),
"FAX NUMBER" VARCHAR(25),
ADDRESS BLOB SUB_TYPE 1,
CITY VARCHAR(50),
"STATE/PROVINCE" VARCHAR(50),
"ZIP/POSTAL CODE" VARCHAR(15),
"COUNTRY/REGION" VARCHAR(50),
"WEB-SITE" VARCHAR(25),
NOTES BLOB SUB_TYPE 1,
INCLUDING BLOB,
CONSTRAINT PK_CLIENTS_ID PRIMARY KEY(ID)
);
'''
s2='''create ascending index IDX_CLIENTS_CITY on CLIENTS (CITY);'''
#os.remove('D:/ThirdTask/test1.fdb')
conn=firebirdsql.create_database(host='localhost', database='/test1.fdb', user='sysdba', password='masterkey')
#con=firebirdsql.connect(host='localhost',database='D:/ThirdTask/test1.fdb', user='sysdba', password='masterkey')
cur=conn.cursor()
cur.execute(s1)
#cur.execute(s2)
conn.commit()
conAcc = pyodbc.connect('DRIVER={Microsoft Access Driver (*.accdb)};DBQ=Northwind.accdb')
conn.close()
结果一开始我收到了一个让我非常困惑的错误
Traceback (most recent call last):
File "D:\ThirdTask\connecttwo.py", line 39, in <module>
conAcc = pyodbc.connect('DRIVER={Microsoft Access Driver (*.accdb)};DBQ=Northwind.accdb')
Error: ('IM002', '[IM002] [Microsoft][\xc4\xe8\xf1\xef\xe5\xf2\xf7\xe5\xf0 \xe4\xf0\xe0\xe9\xe2\xe5\xf0\xee\xe2 ODBC] \xc8\xf1\xf2\xee\xf7\xed\xe8\xea \xe4\xe0\xed\xed\xfb\xf5 \xed\xe5 \xed\xe0\xe9\xe4\xe5\xed \xe8 \xed\xe5 \xf3\xea\xe0\xe7\xe0\xed \xe4\xf0\xe0\xe9\xe2\xe5\xf0, \xe8\xf1\xef\xee\xeb\xfc\xe7\xf3\xe5\xec\xfb\xe9 \xef\xee \xf3\xec\xee\xeb\xf7\xe0\xed\xe8\xfe (0) (SQLDriverConnect)')
翻译成英文的意思是
Error: ('IM002', '[IM002] [Microsoft][Driver Manager ODBC] Data source name not found and no driver specified by default (0)(SQLDriverConnect)')
我使用 32 位 Python 2.7 和 32 位 pyodbc。