Debugging MSSQL Connections from Ubuntu

You might need to install a fair bit of stuff,

sudo apt-get install unixodbc unixodbc-dev tdsodbc freetds-dev freetds-bin -y

There’s a neat trick you can do to automatically configure FreeTDS on you Ubuntu machine (discussion here:

sudo dpkg-reconfigure tdsodbc

This will write data to /etc/odbcinst.ini for you. This file configures which drivers FreeTDS will use. You could write this by hand, but this operation reduces the risk for error.

I was trying to access a remote server using pyodbc and I was providing a connection string like,

import pyodbc
conn = pyodbc.connection('DSN=<dsn>;UID=john.doe;PWD=<password>')

For some reason, I wasn’t able to connect at all. It turns out that I needed to put a space after UID… it’s weird, but it worked. Maybe this is because there was a dot in my UID? I’m not sure. You can also set the UID and PWD in /etc/obcd.ini, but that’s probably not ideal.

If you’re stuck, you can list the connections on a given host with this,

tsql -H <host> -L

You’ll probably need to install tsql, which I think is located in the freetds-bin package listed above.