2016-11-13 29 views
1

我试图添加服务器作为SQL Server故障转移,并且它未使用端口1443,我正在使用端口2776。我试图指定它,但我试过的一切都没有工作。我怎么能这样做?如何指定SQL Server中故障转移合作伙伴服务器的JDBC连接URL中的端口

private String url = "jdbc:sqlserver://server1:2776;DatabaseName=db;failoverPartner=server2"; 

我试过以下配置,但没有一个工作。

  1. ...failoverPartner=server2:2776
  2. ...failoverPartner=server2,2776
  3. ...failoverPartner=server2\\db

但每次我得到异常。

  1. 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.".

  2. 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.".

  3. 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.".

+0

我添加了标签'failover'和'database-mirroring',因为我认为这就是您正在处理的内容...正确吗? –

+0

[这个答案](http://stackoverflow.com/a/12378514/243373)能帮助你吗?不是一个完全相同的问题,但它可能与'failoverPartner'名称中缺少的实例名称有关。 –

+0

另外,你读过这个链接:[使用数据库镜像(JDBC)](https://msdn.microsoft.com/en-us/library/aa342332(v = sql.110).aspx)?也许这里有一些指针? –

回答

1

从文档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.

措辞很容易混淆,但它看起来就像你不能指定故障转移服务器的端口号。


从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.


总之,请执行下列操作之一:

  • 指定故障转移服务器以侦听TCP端口1433。
  • 创建一个命名实例并指定failoverPartnerserver_name\instance_name。确保SQL Server Browser服务正在运行并且端口1434未被阻止。
+0

感谢您的协助。正如你所说,没有办法改变故障转移端口,但通过添加它的工作实例名称。您能否将此添加到您的答案中,以便我可以将其作为解决方案? – davis

+0

@davis完成.... –

相关问题