linux python2.7 mssqlserver_连接到linux上的MSSQL Server 2008

你有你需要的所有软件吗?这就是Ubuntu 12.04所需要的:sudo apt-get install php5-odbc php5-sybase tdsodbc

您在Linux服务器上配置了这些文件吗?(这些是从Ubuntu12.04服务器上获取的)

/etc/odbc.ini# Define a connection to the MSSQL server.

# The Description can be whatever we want it to be.

# The Driver value must match what we have defined in /etc/odbcinst.ini

# The Database name must be the name of the database this connection will connect to.

# The ServerName is the name we defined in /etc/freetds/freetds.conf

# The TDS_Version should match what we defined in /etc/freetds/freetds.conf

[mssql]

Description = MSSQL Server

Driver = freetds

Database = MyDatabase

ServerName = mssql

TDS_Version = 8.0

/etc/odbcinst.ini# Define where to find the driver for the Free TDS connections.

[freetds]

Description = MS SQL database access with Free TDS

Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so

Setup = /usr/lib/i386-linux-gnu/odbc/libtdsS.so

UsageCount = 1

/etc/freetds/freetds.conf# The basics for defining a DSN (Data Source Name)

# [data_source_name]

# host =

# port =

# tds version =

# Define a connection to the MSSQL server.

[mssql]

host = mssql_server_ip_or_domain_name

port = 1433

tds version = 8.0

我读过几篇关于tds版本导致问题的文章。看起来8.0是最好的,但我也看到有人说他们用了7.5和7.0。

然后测试您的连接:isql mssql username password

根据您的环境,您的用户名可能必须采用以下格式:域\用户名

发出命令后,您应该看到如下内容:+---------------------------------------+

| Connected! |

| |

| sql-statement |

| help [tablename] |

| quit |

| |

+---------------------------------------+

SQL>

我认为connect命令应该是这样的(注意:我不知道Python):cnxn = pyodbc.connect('DRIVER=freetds;SERVER=FOOBAR;PORT=1433;DATABASE=T2;UID=FOO;PWD=bar;TDS_Version=8.0;')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值