centos安装freeTDS连接mssql2008

选择正确的TDS版本

在这里插入图片描述
所以我应该找freedsTDS0.85版本以上
参考:http://www.freetds.org/userguide/choosingtdsprotocol.htm#TAB.PROTOCOL.BY.SQLSERVERPRODUCT

去哪里下

https://distfiles.macports.org/freetds/?C=N;O=D
https://pkgs.org/download/freetds
http://www.freetds.org/
我下载的是:freetds-1.1.5.tar.bz2

安装

最好切换到root权限

$ cd freetds-1.1.5/
# 查看当前支持的 tdsver 版本,选择对应支持的 MSSQL 版本
$ ./configure --help
 --with-tdsver=VERSION   TDS protocol version (5.0/7.1/7.2/7.3/7.4/auto)
# 重编译安装,注意 tdsver 版本
$ ./configure --prefix=/usr/local/freetds --enable-msdblib --with-tdsver=7.3
$ make && make install

--prefix=/usr/local/freetds FreeTDS的默认安装目录 /usr/local/freetds
--enable-msdblib 允许 Microsoft 的函数库
--with-tdsver=7.3 指定TDS的协议版本,不填写则默认5.0版,7.3支持MSSQL2008

安装之后

1、 查看FreeTDS 版本

# /usr/local/freetds/bin/tsql -C
Compile-time settings (established with the "configure" script)
                            Version: freetds v1.1.5
             freetds.conf directory: /usr/local/freetds/etc
     MS db-lib source compatibility: yes
        Sybase binary compatibility: no
                      Thread safety: yes
                      iconv library: yes
                        TDS version: 7.3
                              iODBC: no
                           unixodbc: yes
              SSPI "trusted" logins: no
                           Kerberos: no
                            OpenSSL: no
                             GnuTLS: no
                               MARS: yes

2、连接数据库

  • 配置 【如果不配置的话,会出现Server name not found in configuration files.】
$ sudo gedit /usr/local/freetds/etc/freetds.conf
[sqlserver0]
	host = ip地址
	port = 1433
	tds version = 7.3
  • 连接
$ /usr/local/freetds/bin/tsql -S sqlserver1 -U CustomSMS -P SqlMsde@InfoxEie2000
locale is "zh_CN.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Error 20013 (severity 2):
	Unknown host machine name.
There was a problem connecting to the server

原因: host的ip地址写错啦,修改之后就可以了。

$ /usr/local/freetds/bin/tsql -S sqlserver1 -U CustomSMS -P SqlMsde@InfoxEie2000
locale is "zh_CN.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1Error 20009 (severity 9):
	Unable to connect: Adaptive Server is unavailable or does not exist

原因:没有ping通。注意网络必须能够ping到数据库服务器

# /usr/local/freetds/bin/tsql -S sqlserver1 -U CustomSMS -P SqlMsde@InfoxEie2000
locale is "zh_CN.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> 
2> 

http://www.it610.com/article/3825793.html
https://blog.csdn.net/moliyiran/article/details/52926049?utm_source=blogxgwz5

猜你喜欢

转载自blog.csdn.net/zhizhengguan/article/details/89516455