我正在尝试添加一个服务器作为 SQL Server 的故障转移,但它没有使用端口 1443
,我正在使用端口 2776
。我正在尝试指定它,但我尝试的一切都没有用。我怎么能那样做?
private String url = "jdbc:sqlserver://server1:2776;DatabaseName=db;failoverPartner=server2";
我尝试了以下配置,但没有一个起作用。
...failoverPartner=server2:2776
...failoverPartner=server2,2776
...failoverPartner=server2\\db
但每次我都会遇到异常。
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host server2, port 1433 has failed. Error: "connect timed out. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host server2:2776, port 1433 has failed. Error: "null. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host server2, 2776, port 1433 has failed. Error: "null. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".
最佳答案
来自文档 Connecting to SQL Server with the JDBC Driver - Setting the Connection Properties文档,属性failoverPartner
:
Note: The driver does not support specifying the server instance port number for the failover partner instance as part of the failoverPartner property in the connection string. However, specifying the serverName, instanceName and portNumber properties of the principal server instance and failoverPartner property of the failover partner instance in the same connection string is supported.
措辞非常困惑,但看起来您无法为故障转移服务器指定端口号。
来自 Microsoft 的 KB-2284190 ( Applications cannot connect to a mirror partner server when using port number in the failoverPartner attribute of the connection string ) 我读的几乎相同:
CAUSE
Both the error messages occur due to the fact that SQL Server JDBC drivers (all versions) do not support parsing of port number for FailoverPartner connection string attribute and rely on DNS and SQL Server Browser service (for named instances only) to resolve the connection information for the partner server. In environments wherein the conditions discussed in the Symptoms sections are met, the JDBC driver is not able to resolve the partner server information and hence you get the error message discussed above.
This behavior of SQL mirroring infrastructure is by design. For this reason, Microsoft JDBC Driver version 3.0 supports failover partner attribute value only in the format <server_name>[\<SQL_Server_instance_name>].
RESOLUTION
To work around this problem, use one of the following methods in environments where database mirroring is involved:
For default instances of SQL server that are part of mirroring configuration ensure that they are listening on the default port 1433 for TCP connections.
For named instances, ensure that SQL browser service is running and port 1434 is not blocked on the network and server B is not configured as a hidden instance.
最后,执行以下操作之一:
- 指定故障转移服务器在端口 1433 上监听 TCP。
- 创建一个命名实例并将
failoverPartner
指定为server_name\instance_name
。确保 SQL Server Browser 服务正在运行并且端口 1434 未被阻止。
关于java - 如何在 SQL Server 中的 failoverPartner 服务器的 JDBC 连接 URL 中指定端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40576728/