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

时间:2014-06-23 08:20:27

标签: python sql-server ubuntu-12.04 freetds unixodbc

我在32位计算机上运行Ubuntu 12.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/freetds.conf文件:

[TS]
host = 192.168.254.50
port = 1433
tds version = 7.0
client charset = UTF-8

这是我的/etc/odbc.ini文件:

--- /etc/odbc.ini ---
[TS]
Description = "test"
Driver = FreeTDS
Server = 192.168.254.50
Port = 1433
Database = db_name

这是我的/etc/odbcinst.ini文件:

--- /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

有人可以帮帮我吗?

0 个答案:

没有答案
相关问题