6

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
FlipperPA
  • 13,607
  • 4
  • 39
  • 71
Dan Walters
  • 1,218
  • 1
  • 18
  • 30
  • try this https://stackoverflow.com/questions/28566121/pypyodbc-cant-open-lib-freetds-file-not-found-error-when-trying-to-conne – Kenly Nov 08 '17 at 13:24
  • The suggested changes there don't work for me. I'll give pymssql a go however. – Dan Walters Nov 08 '17 at 13:29
  • Not sure but did you try to add a symlink directly in /usr/lib ? `sudo ln -s /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so /usr/lib/libtdsodbc.so` && `sudo ldconfig` . I had problems with other .so librairies during import and it worked for me. – bobolafrite Nov 08 '17 at 14:02
  • @bobolafrite may be onto something. The error message mentions "libtdsodbc.so" without a full path specification, suggesting that UnixODBC may be getting its driver configuration from somewhere other than "/etc/odbcinst.ini". (Also note that it's ".ini", not ".init".) You might try running `odbcinst -j` to check that. – Gord Thompson Nov 08 '17 at 14:53
  • With the symbolic link the webpage just hangs for a while. I added prints to my connection script and they're not being called. It still isn't getting that far. – Dan Walters Nov 08 '17 at 15:30
  • 1
    It appears that UnixODBC is looking for driver definitions in "/usr/local/etc/odbcinst.ini", not "/etc/odbcinst.ini". – Gord Thompson Nov 08 '17 at 16:23
  • 2
    I'd also advise against trying `pymssql` for Django on Linux; the engine hasn't been updated in ages. I'd recommend `django-pyodbc-azure` (even if you're connecting to SQL Server without Azure) here: https://github.com/michiya/django-pyodbc-azure I've used it successfully with unixODBC and FreeTDS for years. – FlipperPA Nov 10 '17 at 14:52

1 Answers1

3

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
Dan Walters
  • 1,218
  • 1
  • 18
  • 30
  • Sept 19 updated link: http://security-cdn.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.0.0_1.0.1t-1+deb8u11_amd64.deb – Dan Walters Sep 09 '19 at 12:56