Unable to connect using pymssql with windows authentication

时光怂恿深爱的人放手 提交于 2019-12-10 21:02:57

问题


While trying to connect to MSSQL Server 2012 using pymssql, I get the following error.

My server name in Windows Authentication is SARATH,User Name is Sarath\SarathShanker and I did not set a password.

Code:

mssql_conn=pymssql.connect(host='SARATH',user='Sarath\SarathShanker',password='',database='matrix')

Error:

Traceback (most recent call last):
File "", line 1, in
File "pymssql.pyx", line 556, in pymssql.connect (pymssql.c:7990)

pymssql.OperationalError: (18452, 'Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.DB-Lib error message 18452 , severity 14:\nGeneral SQL Server error: Check messages from the SQL Server\nDB -Lib error message 20002, severity 9:\nAdaptive Server connection failed\nDB-Lib error message 18452, severity 14:\nGeneral SQL Server error: Check messages fro m the SQL Server\nDB-Lib error message 20002, severity 9:\nAdaptive Server conne ction failed\n')

How should I modify my script in order to connect to MSSQL Server using pymssql.

P.S I have already imported pymssql as well. (Not Shown in Code above)


回答1:


Try this:

conn = pymssql.connect(host='myhost', database='mydb')

This is with Python Version 3.4 and for Windows Authentication.




回答2:


If on RHEL, try

os.environ["FREETDSCONF"] = "/etc/freetds.conf"



回答3:


If you are using the latest version of pymssql (I use 2.1.3),

pymssql.connect(server='<TEST_SERVER>', database='<TEST_DB>')

Simply replace the '' and '' with your server and DB name.



来源:https://stackoverflow.com/questions/16885673/unable-to-connect-using-pymssql-with-windows-authentication

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