Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Applications cannot connect to a mirror partner server when using port number in the failoverPartner attribute of the connection string


Symptoms

Consider the following scenario:
  • You have a client application that is configured to connect to a mirrored database. The client application uses  SQL Server JDBC driver to connect to SQL Server and uses a connection string that is similar to the following:
    jdbc:sqlserver://serverA;databaseName=dbname;failoverPartner=serverB
  • serverB is either a named instance or a default instance that is not listening on the default port for SQL Server, 1433.
  • Either SQL Browser is not running  on serverB or UDP port 1434 is blocked on the network between the client and serverB.
    Note: This condition only affects named instances
  • To ensure connectivity to the serverB,  you  hard code the value of port number  in the Failover Partner attribute of the connection string.
In this scenario, if the serverB becomes the current principal server, client applications may fail to connect or they connect only once and subsequent attempts to connect will fail. Depending on the scenario,  you get one of the following error messages:

Error message 1: You will get the following error message if on the very first connection attempt from  your application, serverA is unavailable and serverB becomes your principal server:

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host has failed. java.net.UnknownHostException
        at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithFailover(Unknown Source)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
        at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)


Error message 2: If  your application initially connects to server but the server becomes unavailable after sometime and serverB becomes your principal server, you get the following error message:

com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the named instance has failed. Error: java.net.SocketTimeoutException: Receive timed out.
        at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.getInstancePort(Unknown Source)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
        at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)

↑ Back to the top


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

↑ Back to the top


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.

↑ Back to the top


More Information



↑ Back to the top


Keywords: kb

↑ Back to the top

Article Info
Article ID : 2284190
Revision : 1
Created on : 1/7/2017
Published on : 8/18/2010
Exists online : False
Views : 133