pythonsqllinuxpyodbcfreetds

Python - Can't open lib 'libtdsodbc.so' : file not found


Any help with this issue is much appreciated.

Goal: Connect Django to MSSQL server using FreeTDS. I'm using a Debian x64 box.

Problem: When trying to make a connection I get the following.

('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'libtdsodbc.so' : file not found (0) (SQLDriverConnect)")

My /etc/odbcinst.ini is configured as followed

[FreeTDS]
Description = FreeTDS
driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so

The files do exist and have 777 access for testing.

The connection string is like

cnxn = pyodbc.connect(
        'DRIVER={FreeTDS};SERVER=' + server + ';PORT=1443;DATABASE=' + database + ';UID=' + username + ';PWD=' + password)
    cursor = cnxn.cursor()

My odbcinst -j reads (since adding symlink)

unixODBC 2.3.1
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

Solution

  • If anyone else runs into this hurdle, check out this blog post.

    https://emacstragic.net/2017/11/06/mssql-odbc-client-on-debian-9-stretch/

    Essentially, I had to target a specific libssl version for it to work.

    Looking at the installed versions i found:

    ldd /opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.9.1 | grep 'not found'
    libcrypto.so.1.0.0 => not found
    libssl.so.1.0.0 => not found
    

    and manually installing a previous version fixed the issue

    wget "http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.0.0_1.0.1t-1+deb8u7_amd64.deb"
    sudo apt install ./libssl1.0.0_1.0.1t-1+deb8u7_amd64.deb