導讀
下載地址:http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
這個軟件能夠用Linux和Unix連接MS SQLServer和Sybase數據庫
安裝與配置
-
首先下載FreeTDS安裝包到服務器
wget -c http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
-
解壓
tar -zxvf freetds-stable.tgz
-
編譯安裝
-
因為是編譯安裝所以確保機器有安裝gcc(可使用yum進行安裝)
yum install gcc-c++ yum install ncurses-devel
-
開始安裝
cd freetds-0.91/ ./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib make && makeinstall
解釋: 安裝freetds到目錄/usr/local/freetds:--prefix=/usr/local/freetds 支持MSSQL2000:--with-tdsver=8.0 --enable-msdblib
-
-
FreeTDS默認安裝在/usr/local/freetds目錄當中,庫文件在相應的lib目錄下。
vim /etc/ld.so.conf
加入一行/usr/local/freetds/lib
-
然后運行以下指令使更改生效:
ldconfig
-
測試連接
tsql -H MSSQL服務器服務IP -p 1433 -U MSSQL服務器登陸帳號 -P MSSQL服務器登陸密碼
$ tsql -H XXXXXX-p 1433 -U sa -P XXXXXX -D test locale is "zh_CN.utf8" locale charset is "UTF-8" Default database being set to test 1> select @@version 2> go Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (Intel X86) Apr 2 2010 15:53:02 Copyright (c) Microsoft Corporation Data Center Edition on Windows NT 5.1 <X86> (Build 2600: Service Pack 3) (1 row affected)
問題
Adaptive Server connection failed
locale is "en_US.UTF-8" locale charset is "UTF-8" using default charset "UTF-8" Error 20017 (severity 9): Unexpected EOF from the server OS error 115, "Operation now in progress" Error 20002 (severity 9): Adaptive Server connection failed There was a problem connecting to the server
執行
tsql -C
[root@thinkpa freetds-0.91]# tsql -C Compile-time settings (established with the "configure" script) Version: freetds v0.91 freetds.conf directory: /usr/local/etc MS db-lib source compatibility: no Sybase binary compatibility: no Thread safety: yes iconv library: yes TDS version: 5.0 iODBC: no unixodbc: no SSPI "trusted" logins: no Kerberos: no
發現freetds的版本是5.0,考慮到可能是freetds版本的問題
兩種解決方式:
-
修改全局TDS 版本號
找到
/usr/local/etc/freetds.conf
修改[global]
下面的tds version
為8.0
-
連接時修改tds版本號
TDSVER=7.0 tsql -H
整個連接命令則變為:
tsql -H MSSQL服務器服務IP -p 1433 -U MSSQL服務器登陸帳號 -P MSSQL服務器登陸密碼
Adaptive Server connection failed
"Cannot open server 'xxxxxxx' requested by the login. Client with IP address 'xxxxxxxxx' is not allowed to access the server. To enable access, use the Windows Azure Management Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range. It may take up to five minutes for this change to take effect." Error 20002 (severity 9): Adaptive Server connection failed
這個毋庸置疑了,找管理員開通白名單再訪問吧!
-