使用freetds、unixodbc和python连接到MS SQL数据库

使用freetds、unixodbc和python连接到MS SQL数据库,python,sql-server,ubuntu-12.04,freetds,unixodbc,Python,Sql Server,Ubuntu 12.04,Freetds,Unixodbc,我在32位计算机上运行Ubuntu12.04,我想使用freetds、unixodbc和python连接到我的MS SQL数据库,但我遇到了一个错误: >>> import pyodbc >>> conn = pyodbc.connect('DSN=TS;UID=myusername;PWD=mypassword') Traceback (most recent call last): File "<stdin>", line 1, in &l

我在32位计算机上运行Ubuntu12.04,我想使用freetds、unixodbc和python连接到我的MS SQL数据库,但我遇到了一个错误:

>>> import pyodbc
>>> conn = pyodbc.connect('DSN=TS;UID=myusername;PWD=mypassword')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')
这是我的
/etc/odbc.ini
文件:

[TS]
host = 192.168.254.50
port = 1433
tds version = 7.0
client charset = UTF-8
--- /etc/odbc.ini ---
[TS]
Description = "test"
Driver = FreeTDS
Server = 192.168.254.50
Port = 1433
Database = db_name
--- /etc/odbcinst.ini ---
[FreeTDS]
Description = FreeTDS
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
这是我的
/etc/odbcinst.ini
文件:

[TS]
host = 192.168.254.50
port = 1433
tds version = 7.0
client charset = UTF-8
--- /etc/odbc.ini ---
[TS]
Description = "test"
Driver = FreeTDS
Server = 192.168.254.50
Port = 1433
Database = db_name
--- /etc/odbcinst.ini ---
[FreeTDS]
Description = FreeTDS
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
当我尝试使用
tsql
在bash上测试这一点时,它可以工作:

$ tsql -S TS -U myusername -P mypassword
locale is "en_SG.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> use db_name
2> go
1> select top 10 label from db_name.tablename
2> go
[... data here ...]
(10 rows affected)
1> 
但是,使用
isql
对其进行测试时,会出现与python提示符中非常类似的错误:

$ isql -v TS myusernam mypassword
[IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified
[ISQL]ERROR: Could not SQLConnect
有人能帮我吗