一 測(cè)試環(huán)境
操作系統(tǒng) Red Hat As 5.5
數(shù)據(jù)庫(kù)
SQLServer2000 installed in windows xp professional,我假定數(shù)據(jù)庫(kù)有用戶autotest 密碼是autotest,數(shù)據(jù)庫(kù)文件是atsdb
注意:
1 MS從來沒有提供過SQLServer for Linux,所以大家也不要去嘗試在Linux系統(tǒng)安裝SQLServer,但是可以通過ODBC連接
Windows系統(tǒng)的SQLServer數(shù)據(jù)庫(kù);
2 安裝的SQLServer2000是不會(huì)打開1433端口的,所以請(qǐng)Windows xp 用戶在安裝完SQLServer之后一定裝上SQLServer SP3布丁,可以使用命令netstat -a 來查看是否打開1433端口
3 對(duì)于windows xp,缺省防火墻是不讓1433端口來通訊的,所以必須關(guān)掉windows的防火墻,這個(gè)問題折騰我一天,老是連接不成功,我還以為是odbc軟件的配置 問題,教訓(xùn)呀。最可氣的是在別的windows機(jī)器使用sqlserver的命令isql能夠訪問數(shù)據(jù)庫(kù),(不用關(guān)閉防火墻)。通過抓包工具發(fā)現(xiàn)根本就不 通過1433端口通訊,而是通過445或139內(nèi)部端口通訊呀,真要命呀,看來windowns東西是好,但是也太霸道了呀
4 在xp sp2安裝sqlserver2000時(shí)必須要打chs_sql2ksp3.exe補(bǔ)丁,如果沒有這個(gè)補(bǔ)丁,telnet ip 1433會(huì)連接不了,當(dāng)然從遠(yuǎn)程客戶端連接不上,就這個(gè)問題折騰一個(gè)下午,暈呀
Linux系統(tǒng)的ODBC
unixODBC-2.2.8.tar.gz ( http://www.unixodbc.org)
連接SQLServer或Sybase的驅(qū)動(dòng)
freetds-0.62.4.tar.gz ( http://www.freetds.org)
二 安裝配置(必須在root下用戶安裝)
1、安裝unixODBC
# tar vxzf unixODBC-2.2.8.tar.gz
# cd unixODBC-2.2.8
# ./configure --prefix=/usr/local/unixODBC --enable-gui=no
# make
# make install
2、安裝freetds
# tar vxzf freetds-0.62.4.tar.gz
# cd freetds-0.62.4
# ./configure --prefix=/usr/local/freetds --with-unixodbc=/usr/local/unixODBC --with-tdsver=8.0
# make
# make install
3、配置freetds
# vi /usr/local/freetds/etc/freetds.conf
修改以下的一段,并把;去掉
改好之后的內(nèi)容:
[global]
# TDS protocol version
tds version = 8.0
[SQLServer2000]
host = 192.168.1.110
port = 1433
tds version = 8.0
client charset = ISO-8859-1
[SQLServerMDM]
host =SQLCNBJ015.corp.novocorp.net
port =3888
# instance = MDM_StagingDB
tds version = 8.0
client charset = UTF-8
其中的[SQLServer2000]代表在客戶端使 用的服務(wù)器名稱(在tsql命令中要加入 -S SQLServer2000),host代表SQLServer服務(wù)器的IP地址,port代表端口.client charset 是客戶端使用的字符集,我的機(jī)器使用utf-8會(huì)報(bào)連接失敗的錯(cuò)誤,發(fā)現(xiàn)tsql使用ISO-8859-1字符集可以連接成功,所以這兒也改成這樣
測(cè)試連接:
$ tsql -S SQLServer2000 -U autotest -P autotest
./tsql -S SQLServerDEV -U SELASReader -P Only4SELAS
locale is "en_US"
locale charset is "ISO-8859-1"
Msg 2403, Level 16, State 0, Server OpenClient, Line 0
WARNING! Some character(s) could not be converted into client"s character set. Unconverted bytes were changed to question marks ("?").
1> use atsdb
2> go
1> select * from auth_function
2> go
FUNC_ID NAME ENGLISH_NAME PARENT_ID IS_LOG NOTES
1>
[siebel@appcnbj035 bin]$ ./tsql -S SQLServerMDM -U SELASReader -P Only4SELAS
locale is "LC_CTYPE=en_US.UTF-8;LC_NUMERIC=zh_CN.GB18030;LC_TIME=zh_CN.GB18030;LC_COLLATE=zh_CN.GB18030;LC_MONETARY=zh_CN.GB18030;LC_MESSAGES=zh_CN.GB18030;LC_PAPER=zh_CN.GB18030;LC_NAME=zh_CN.GB18030;LC_ADDRESS=zh_CN.GB18030;LC_TELEPHONE=zh_CN.GB18030;LC_MEASUREMENT=zh_CN.GB18030;LC_IDENTIFICATION=zh_CN.GB18030"
locale charset is "UTF-8"
Msg 5703, Level 0, State 1, Server SQLCNBJ015\I01, Line 1
Changed language setting to us_english.
1> select count(*) from V_Standard_STAFF ;
2> go;
這說明安裝freetds成功
4、配置unixODBC
# cd /usr/local/unixODBC/etc
向ODBC添加SQLServer驅(qū)動(dòng)
# vi /usr/local/unixODBC/etc odbcinst.ini
寫入如下內(nèi)容:
[ODBC]
Trace = Yes
TraceFile = /tmp/sql.log
ForceTrace = Yes
Pooling = No
[SQLSERVER]
Description = SQLSERVER
Driver = /usr/local/freetds/lib/libtdsodbc.so
Setup = /usr/local/freetds/lib/libtds.so
UsageCount = 1
CPTimeout = 5
CPReuse = 5
FileUsage = 1
保存退出
添加DSN
# vi /usr/local/unixODBC/etc/odbc.ini
寫入如下內(nèi)容
[ATSDB]
Driver = SQLSERVER
Description = SQLSERVER
Server = 192.168.1.110
Database = atsdb
Port = 1433
[ATSDB] = SQLSERVER
Description = SQLSERVER
Server = SQLCNBJ015.corp.novocorp.net
Database = MDM_StagingDB
Port = 3888
注意Driver驅(qū)動(dòng)要寫odbcinst.ini中的驅(qū)動(dòng)名稱,Database是數(shù)據(jù)庫(kù)的名稱
保存并退出。
測(cè)試ODBC的連接
# bin/isql -v ATSDB autotest autotest
Cd /usr/local/unixODBC/bin
./isql -v ATSDB SELASReader Only4SELAS
SQL>
SQL> quit
您可能感興趣的文章:- ADO.NET 連接數(shù)據(jù)庫(kù)字符串小結(jié)(Oracle、SqlServer、Access、ODBC)
- php5.3中連接sqlserver2000的兩種方法(com與ODBC)
- SQL SERVER使用ODBC 驅(qū)動(dòng)建立的鏈接服務(wù)器調(diào)用存儲(chǔ)過程時(shí)參數(shù)不能為NULL值