与远程MS SQLServer的java JDBC连接失败
我正在测试一个示例Java代码,以连接到MS SQL Server数据库并获取一些数据当我在承载SQL Server的同一系统中执行代码时,代码工作正常,但当我通过VPN从另一个系统执行同一程序时,代码无法连接
以下是我收到的错误:
com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the host SQLServerHost.Domain.com, named instance myInstance failed. Error: "java.net.SocketTimeoutException: Receive timed out". Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434.
在SQL Server启动并运行的系统中:
- 服务:SQL Server浏览器、SQL Server(myInstance)和SQL Server代理(myInstance)正在运行李>
- 在SQL Server配置管理器中->;SQL Server网络配置->;myInstance的协议: a、 TCP/IP已启用。 b、 IPALL:TCP动态端口设置为空白,TCP端口设置为1433。 c、 指定域IP地址的IP6:TCP Dynamics port设置为blank,TCP port设置为1433李>
- 添加了入站连接的防火墙规则: a、 允许连接到端口1433。 b、 允许连接到程序D:\Program Files\Microsoft SQL Server\MSSQL12。MyInstance\MSSQL\Binn\Sqlservr。exe李>
以下是代码示例:
import java.sql.*;
public class FirstExample {
// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
static final String DB_URL = "jdbc:sqlserver://SQLServerHost.Domain.COM\\myInstance;databaseName=myDatabase";
// Database credentials
static final String USER = "myuser";
static final String PASS = "mypwd";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{
Class.forName(JDBC_DRIVER);
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL,USER,PASS);
/*Error: "java.net.SocketTimeoutException: Receive timed out" is reported at above getConnection call*/
..............
..............
}//FirstExample
使用的mssql jdbc jar是mssql-jdbc-7.0.0。jre8。罐子
编辑1: 在承载SQL Server的系统中,添加了入站连接的防火墙规则,以允许UDP端口1434。然而,这个设置也没有帮助
谢谢
共 (0) 个答案