我尝试通过SSH隧道使用tiny_tds Ruby gem连接到远程SQL Server 2008 R2,如下所示:
require 'tiny_tds'
require 'net/ssh/gateway'
gateway = Net::SSH::Gateway.new(
'host',
'username',
port: 'port',
password: 'password'
)
port = gateway.open('127.0.0.1', 1433, 1234) # SQL Server uses 1433 port
db_client = TinyTds::Client.new(
host: '127.0.0.1',
username: 'username',
password: 'password',
port: 1234,
database: 'database'
) # => TinyTds::Error: Adaptive Server connection timed out (127.0.0.1:1234)
我得到了上面的例外。虽然,如果我尝试从控制台SSH到Windows机器并尝试使用sqlcmd
连接到SQL Server - 一切正常。