freetds and pyodbc failing to connect freetds and pyodbc failing to connect linux linux

freetds and pyodbc failing to connect


Setup looks fine. I had a similar thing working, which broke after the server upgraded to NTLMv2. This gave an "...untrusted domain..." error when testing tsql. * detail here

I only had to include use ntlmv2 = yes in my freetds.conf spec.


Using Windows Authentication can be tricky... and very ugly. For best practices:

  • Create a SQL Authenticated user in SQL Server to connect with as limited privileges as possible.

  • A side note, TDS Version 8.0 will work, but for the sake of being correct, you should use TDS Version 7.2: https://www.freetds.org/userguide/ChoosingTdsProtocol.html

  • The TDS Version has changed in 2012 and 2014, but is backwards compatible. I haven't had any issues with pyodbc with 2012 or 2014 with Django.

  • You will also need to change this line to include the TDS Version:

    cnxn = pyodbc.connect('DRIVER=FreeTDS;SERVER=same_ip_as_above;DATABASE=Reports;UID=myusername;PWD=mypassword;TDS_Version=7.2;')

Best of luck; I believe if you fix that, the rest of the stack should behave.

Regards,

-Tim