//jerrywalsh.org

coding, hacking, startups, computer security, technology and more

Using FreeTDS With Ruby-odbc on Debian Linux

I recently was upgrading a Ruby on Rails installation from 3.2 to 5.2 and as is normal lots of stuff had changed. This particular project involves the use of ruby-odbc and tiny-tds along with activerecord-sqlserver-adapter to provide connectivity to Microsoft SQL server.

The ruby ODBC & TDS gems took quite a version jump after upgrading and required a newer version of FreeTDS than was available via the apt repositories (debian backports was no help either). As a result the only option is to fetch, compile and install freetds yourself. It's always nice to have things configured in an easily reproducible way and so this little script performs the necessary. Simply adjust the version variables (V) and execute the script as root. You should of course ensure you've removed the native freetds-common and freetds-dev packages before you do this. I hope you find it useful.

simple script to compile and install the latest version of FreeTDS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh
# fetch and compile freetds from source because the version available from the debian apt
# repository isn't current enough, enter your freetds tarball version string here:
V="freetds-1.00.87"
# --- and begin...
set -e
cd /tmp/
test -e "$V".tar.gz || wget http://www.freetds.org/files/stable/"$V".tar.gz
test -d "$V" || tar xvfzp "$V".tar.gz
cd "$V"

# Enable openssl (recommended):
./configure --prefix=/usr/ --with-tdsver=7.4 --with-openssl --sysconfdir=/etc/

# Disable openssl (not recommended but may be desirable if you're connecting to
# older SQL clients which don't support ciphers which are considered strong enough)
# if you're getting "client library returned TDS_INT_CANCEL" and lowering
# openssl ciphers to the lowest possible setting won't work THEN consider this
# otherwise, leave openssl enabled :)
#./configure --prefix=/usr/ --with-tdsver=7.4 --with-openssl=no --without-openssl --sysconfdir=/etc/
make
make install

Note as indicated in the script above, if you're receiving a client library returned TDS_INT_CANCEL error during connect then this is probably related to the openssl ciphers you're using. You should adjust the ciphers used on either your server or client library so they're compatible.