3

I have FreeTDS installed and configured correctly. My freetds.conf file as this appended to the end:

[myserver]
    host = myserver
    port = 1433
    tds version = 7.0

And I can running the following command gives me a SQL prompt:

tsql -S myserver -U username

My python script is extremely minimal, in an attempt to successfully connect to the database:

#! /path/to/python/bins

import pymsql
conn = pymssql.connect(host='myserver', user='username', password='password', database='database', as_dict=True)
conn.close()

But when I run it I recieve the following error:

Traceback (most recent call last):
  File "./test.py", line 5, in <module>
    conn = pymssql.connect(host='myserver', user='username', password='password', database='database', as_dict=True)
  File "pymssql.pyx", line 456, in pymssql.connect (pymssql.c:6017)
pymssql.InterfaceError: Connection to the database failed for an unknown reason.

What could cause this? From what I've searched, most people who run into this problem have the freetds.conf file configured incorrectly; however, I can successfully connect (with tsql). Does anyone know what I'm doing wrong, or how I can fix this?

1 Answer 1

4
+50

I have just looked through pymssql code and most likely you have problem with MSSQL driver. https://code.google.com/p/pymssql/source/browse/pymssql.pyx?name=1.9.908#456

Try configuring logging in FreeTDS to see "unknown reason": see http://freetds.schemamania.org/userguide/logging.htm (mirror)

Basically:

$ export TDSDUMP=/tmp/freetds.log
Sign up to request clarification or add additional context in comments.

3 Comments

It looks like it isn't trying to connect on the port I specified in the freetds.conf file: net.c:210:Connecting to <server-ip> port 4000 (TDS version 5.0)
I figured out one way to get a connection (although I am now getting other errors); I just need to specify the port in the python code. So where I have host=myserver, I would have host=myserver:port. Although all of my problems aren't solved, the one I was asking about is. Thanks!
I should also note that I had to create the following env variable: TDSVER=8.0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.