2016-11-13 86 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完成.... –