Fading Coder

An Old Coder’s Final Dance

Home > Tech > Content

Installing FreeTDS on CentOS for SQL Server and Sybase Access

Tech 4

FreeTDS is an open-source implemantation of the Tabular Data Stream (TDS) protocol used by Microsoft SQL Server and Sybase. It provides command-line utilities (such as tsql) and client libraries for applications.

  • Project site: https://www.freetds.org
  • Stable source tarball: http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz

Prerequisites

Ensure build tools and headers are available:

sudo yum install -y gcc gcc-c++ make
sudo yum install -y ncurses-devel

If your environment requires iconv or SSL, also install:

sudo yum install -y libiconv-devel openssl-devel

Download and unpack the source

cd /usr/local/src
sudo wget -c http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
sudo tar -xzf freetds-stable.tgz
cd freetds-*/

Configure, build, and install

Choose an installation prefix and a default TDS protocol version. For modern SQL Server, 7.3 or 7.4 is typical; for very old servers, 7.0/8.0 may be required.

PREFIX=/usr/local/freetds
DEFAULT_TDS=7.3

./configure \
  --prefix="${PREFIX}" \
  --with-tdsver="${DEFAULT_TDS}" \
  --enable-msdblib

make -j"$(nproc)"
sudo make install

Notes:

  • --prefix sets the install location (binaries, headers, and libarries under ${PREFIX}).
  • --with-tdsver defines the default protocol used by clients if not overridden.
  • --enable-msdblib enables Microsoft DB-Library compatibiilty.

Expose the libraries to the dynamic linker

Add the library directory to the system’s loader configuration and refresh the cache:

echo "${PREFIX}/lib" | sudo tee /etc/ld.so.conf.d/freetds.conf >/dev/null
sudo ldconfig

Verify the build

Check compile-time settings:

${PREFIX}/bin/tsql -C

Example output (values will vary):

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

Test connectivity with tsql

You can set the TDS version per-invocation or rely on the compiled default. For SQL Server on port 1433:

# Optionally override protocol version for this run
export TDSVER=7.3

${PREFIX}/bin/tsql -H <server_or_ip> -p 1433 -U <login> -P <password> -D <database>

Interactive example:

$ ${PREFIX}/bin/tsql -H 192.0.2.10 -p 1433 -U sa -P ******** -D test
locale is "en_US.utf8"
locale charset is "UTF-8"
Default database being set to test
1> select @@version
2> go

Microsoft SQL Server 2019 (RTM-CU*) ...
(1 row affected)

Troubleshooting

"Unexpected EOF" or "Adaptive Server connection failed"

This frequently indicates a protocol mismatch. Confirm the compiled default and config directory:

${PREFIX}/bin/tsql -C

Fix options:

  • Set the TDS version for a single session:
TDSVER=7.0 ${PREFIX}/bin/tsql -H <host> -p 1433 -U <login> -P <password>
  • Make a global change in freetds.conf. Locate the config directory from tsql -C (often /usr/local/etc) and set a global default:
# /usr/local/etc/freetds.conf
[global]
    tds version = 7.3

Try 7.0, 7.1, 7.2, 7.3, or 7.4 depending on the database version. If connecting to Sybase, 5.0 may be appropriate.

Also verify network reachability and that the server listens on the expected port.

Azure SQL or firewall-related denial

If you encounter an error similar to:

Cannot open server 'XXXX' requested by the login. Client with IP address 'A.B.C.D' is not allowed to access the server. To enable access, use the Azure portal or run sp_set_firewall_rule on the master database. It may take up to five minutes for this change to take effect.
Error 20002 (severity 9):
        Adaptive Server connection failed

Permit the client IP in the server’s firewall rules (e.g., Azure portal) or execute sp_set_firewall_rule against the master database, then retry after the rule propagates.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.