我有以下代码:
import pyodbc
cnxn = pyodbc.connect("DRIVER={SQL Server};"
+"SERVER=something.example.com;"
+"DATABASE=something;")
cursor = cnxn.cursor()
name=('Smith, Joe', )
cursor.execute('SELECT id FROM Users WHERE displayname=?', name)
rows = cursor.fetchall()
for row in rows:
print row
代码在 windows/python2.7 上根据需要执行。但是,当我尝试在 linux 上运行它时,出现以下错误:
Traceback (most recent call last):
File "/something/script.py", line 125, in <module>
main()
File "/something/script.py", line 77, in main
+"DATABASE=something;")
pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnectW)')
回溯似乎表明该DRIVER
条目丢失,事实并非如此。这是版本差异吗?pyodbc有什么问题?
编辑:/etc/odbcinst.ini 的内容:
# Example driver definitions
# Driver from the postgresql-odbc package
# Setup from the unixODBC package
[PostgreSQL]
Description = ODBC for PostgreSQL
Driver = /usr/lib/psqlodbc.so
Setup = /usr/lib/libodbcpsqlS.so
Driver64 = /usr/lib64/psqlodbc.so
Setup64 = /usr/lib64/libodbcpsqlS.so
FileUsage = 1
# Driver from the mysql-connector-odbc package
# Setup from the unixODBC package
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc5.so
Setup = /usr/lib/libodbcmyS.so
Driver64 = /usr/lib64/libmyodbc5.so
Setup64 = /usr/lib64/libodbcmyS.so
FileUsage = 1