无法使用JDBC连接通过SSH隧道连接到Azure DB

时间:2020-06-05 15:11:36

标签: jdbc azure-sql-database ssh-tunnel

我无法使用JDBC连接通过SSH隧道连接到Azure数据库。 出于安全原因,我不能直接访问Azure数据库,但是有一个跳转服务器/隧道VM,可用于间接连接到数据库。

  • 通过隧道VM对Azure数据库进行命令行访问(通过JDBC)
  • 如果我使用使用MS OLE DB SQL驱动程序的客户端,则建立SSH隧道(ssh -f vm_user@tunnel_vm_host -L 127.0.0.1:1433:mydb-server.database.windows.net:1433 -N),然后通过127.0.0.1:1433dbuser@mydb-server.database.windows.net连接到Azure DB是可行的
  • 使用MS SQL JDBC驱动程序建立连接失败:com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host xxx.yyy.zzz.worker.database.windows.net, port 11111 has failed. Error: "Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
  • 从Wireshark可以看到,如果使用JDBC驱动程序,则使用隧道(127.0.0.1:randomport <--> 127.0.0.1:1433)开始与Azure DB的通信,然后使用{{1}切换到隧道外部},由于防火墙而失败。

要运行此程序,我缺少什么?

使用的驱动程序:

  • JDBC驱动程序版本是mssql 8.2.2.0 jre11
  • 用于SQL Server 18.3.0.0的MS OLE DB驱动程序

测试程序:

my-external-IP:randomport <--> xxx.yyy.zzz.worker.database.windows.net:11111

1 个答案:

答案 0 :(得分:1)

数据库服务器的连接策略必须为代理,才能使用ssh隧道。

有关可用连接策略差异的详细信息,请参见Azure SQL Database and Azure Synapse Analytics connectivity architecture文章。