在Linux上如何安装freetds?

25

我正在尝试从Ubuntu连接到MSSQL服务器。 我已经像这里建议的那样安装了freetds。

输入图像描述

然而,当我尝试配置/etc/odbc.ini并输入驱动程序路径时,我在位置/usr/local/freetds/lib/libtdsodbc.so找不到驱动程序。

输入图像描述

有人能帮我安装freetds并配置odbc以使用它吗? *编辑1:我已在/usr/lib/x86_64-linux-gnu/odbc中找到libtdsodbc.so。 我应该使用那个驱动程序/路径吗?


1
请查看我在这里所遵循的步骤,希望能对您有所帮助:http://stackoverflow.com/questions/34725523/working-with-nodejs-mssql-at-linux-ubuntu - Hasan A Yousef
3个回答

35
我创建了一个 Vagrant box,这里有一个完整的安装示例:https://github.com/FlipperPA/django-python3-vagrant/ ...但是以下是基本步骤。
(注意:将 dbserver.domain.com 更改为您的服务器主机名或 IP)
# Install pre-requesite packages
sudo apt-get install unixodbc unixodbc-dev freetds-dev freetds-bin tdsodbc

将odbcinst.ini中的指针指向/etc/odbcinst.ini中的驱动程序。
[FreeTDS]
Description = v0.91 with protocol v7.2
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so

在/etc/odbc.ini中创建您的DSN:
[dbserverdsn]
Driver = FreeTDS
Server = dbserver.domain.com
Port = 1433
TDS_Version = 7.2

...以及在/etc/freetds.conf中的DSN配置:
[global]
    # TDS protocol version, use:
    # 7.3 for SQL Server 2008 or greater (tested through 2014)
    # 7.2 for SQL Server 2005
    # 7.1 for SQL Server 2000
    # 7.0 for SQL Server 7
    tds version = 7.2
    port = 1433

    # Whether to write a TDSDUMP file for diagnostic purposes
    # (setting this to /tmp is insecure on a multi-user system)
;   dump file = /tmp/freetds.log
;   debug flags = 0xffff

    # Command and connection timeouts
;   timeout = 10
;   connect timeout = 10
    
    # If you get out-of-memory errors, it may mean that your client
    # is trying to allocate a huge buffer for a TEXT field.  
    # Try setting 'text size' to a more reasonable limit 
    text size = 64512

# A typical Microsoft server
[dbserverdsn]
    host = dbserver.domain.com
    port = 1433
    tds version = 7.2

完成后,您可以通过尝试使用tsql(用于测试FreeTDS层)和isql(用于通过FreeTDS堆栈测试unixODBC)来测试您的连接。

3
我是新手。我应该将Server = dbserver.domain.com更改为我的服务器IP吗?这样我才能使用tsql tsql -S dbserverdsn,还是应该在那里写IP?当我使用tsql -S dbserverdsn时,我得到了Error 100 (severity 11): unrecognized msgno Error 20009 (severity 9):Unable to connect: Adaptive Server is unavailable or does not exist OS error 111, "Connection refused" There was a problem connecting to the server的错误信息。 - Hrvoje T
请执行以下命令:tsql -S dbserverdsn <userid> <password> - Apit John Ismail
3
我使用 tsql -C 命令检查了 TDS 版本,发现它是 4.2。我将上面的 7.2 替换为 4.2,这似乎解决了 msgno error 的问题。 - Jay Killeen
1
@FlipperPA - 哇,谢谢你提供的解决方案!我终于能够在 Linux Mint 桌面上连接 QGIS Destop 和 MS SQL Server,这是我近十年来一直无法解决的问题! - DPSSpatial

22

通过apt-get可获得的版本实在太老了。要获取更新版本:

sudo apt-get install wget
sudo apt-get install build-essential
sudo apt-get install libc6-dev

# find latest version of FreeTDS ftp://ftp.freetds.org/pub/freetds/stable/

wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-1.2.tar.gz
tar -xzf freetds-1.2.tar.gz
cd freetds-1.2
./configure --prefix=/usr/local --with-tdsver=7.3
sudo make
sudo make install

1
仅供参考:当前稳定版本为1.12(2019/07)。 - ˈvɔlə
非常有用,谢谢! - Masiorama
在Ubuntu 22.10上工作!非常感谢! - Sergio Belevskij

0

在freedts.conf文件中

[Server80]
        host = example.com
        port = 1433
        tds version = 8.0
        client charset = UTF-8

in odbc.ini

[MSSQL8]
Driver          = FreeTDS
Description     = Sybase JDBC Server
Trace           = No
Servername      = Server80
Database        = DBNAME
UID             = sa
ClientCharset   = UTF-8

在odbcinst.ini文件中

[FreeTDS]
Description=v0.63 with protocol v8.0
Driver=/usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
UsageCount=2

4
似乎使用 sudo apt install -y freetds-bin 进行工作! - Peter Krauss

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接