Cannot connect to mssql db using pymssql

两盒软妹~` 提交于 2019-12-22 10:56:09

问题


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:


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


来源:https://stackoverflow.com/questions/17662680/cannot-connect-to-mssql-db-using-pymssql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!