sql-serversshpymssql

pymssql cannot connect to an ssh forwarded SQL Server


I need to access a SQL Server that is in a network that I do not directly have access to. However, I have SSH access to a host that does have access to this SQL Server. In other cases, I have used an SSH LocalForward to forward the SQL Server's port locally on 127.0.2.3:11433 and this has worked fine.

In this particular instance, however, it does not, and it always throws an OperationalError when doing

pymssql.connect("127.0.2.3:11433", "user", "password")

pymssql.exceptions.OperationalError: (20002, b'DB-Lib error message 20002, severity 9:
Adaptive Server connection failed (127.0.2.3)
DB-Lib error message 20002, severity 9:
Adaptive Server connection failed (127.0.2.3)

However, if I use the node-based mssql commandline utility, I can connect to the SSH-forwarded server.

When I go onto the server that I have SSH access to and I do the same thing from there (adjusting the port and IP address of course), I do get access.

So in short, the problem occurs with:

Might it be a bug in pymssql? Filed here: https://github.com/pymssql/pymssql/issues/888


Solution

  • First please update to the latest pymssql version - 2.3.0. Then, try different tds_version like here #860. If it still fails, then set environment variable TDSDUMP/TDSCONFIIG and try to analyze the logs. See FreeTDS logging