Search code examples
pythonsql-serverbashubuntupymssql

Use Python pymssql from Ubuntu bash


I have installed Ubuntu bash on my Windows 10

I can access python3 from there, and everything seems ok

the problem i am facing at the moment is connect to MS SQL Server through Python pymssql.

I can connect from my Spyder perfectly but when I use the same script in Ubuntu bash I get this error

>>> conn = pymssql.connect(server="MyServer", database="MyDB")
Traceback (most recent call last):
  File "src/pymssql.pyx", line 636, in pymssql.connect
  File "src/_mssql.pyx", line 1957, in _mssql.connect
  File "src/_mssql.pyx", line 676, in _mssql.MSSQLConnection.__init__
  File "src/_mssql.pyx", line 1683, in _mssql.maybe_raise_MSSQLDatabaseException
_mssql.MSSQLDatabaseException: (20002, b'DB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (MyServer:1433)\n')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "src/pymssql.pyx", line 642, in pymssql.connect
pymssql.OperationalError: (20002, b'DB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (MyServer:1433)\n')

Anyone has an idea how to fix that?


Solution

  • I found the problem

    I cannot access SQL DB with Windows Authentication

    I used a User ID and Pwd to fix that

    conn = pymssql.connect(server="MyServer", database="MyDB", port="1433", user="MyUser", password="MyPwd")