Answer the question
In order to leave comments, you need to log in
How to connect to MSSQL via SSH tunnel from Python script?
Hello.
This is how the tunnel rises, the connection with MSSQL, as it were, is trying to be established, but that's all and the connection ends endlessly in the pending state:
import pymssql
from sshtunnel import SSHTunnelForwarder
from time import sleep
def query():
with SSHTunnelForwarder(
('111.222.333.444', 22),
ssh_username='ssh-user',
ssh_password='ssh-pass',
remote_bind_address=('192.168.0.2', 1433),
local_bind_address=('127.0.0.1', 1433),
) as tunnel:
print(tunnel)
connection = pymssql.connect(server='127.0.0.1', port='1433', user='user', password='pass', database='base')
cursor = connection.cursor(as_dict=True)
cursor.execute('SELECT id_country id, name title FROM dbo.Country WHERE id_country > 0')
for row in cursor:
print(row['title'])
sleep(2)
connection.close()
sleep(10)
print('FINISH!')
query()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question