Extended connection failover provides failover protection for the following types of connections:
New connections (in the same way as described in "Connection failover")
Lost connections
When a connection to the database is lost, the driver fails over the connection to an alternate server, restoring the same state of the connection at the time it was lost. For example, when reestablishing a lost connection on the alternate database server, the driver performs the following actions:
Restores the connection using the same connection properties specified by the lost connection
Reallocates statement handles and attributes
Logs in the user to the database with the same user credentials
Restores any prepared statements associated with the connection
Restores manual commit mode if the connection was in manual commit mode at the time of the failover
The driver does not preserve work in progress. For example, if the database server experienced a hardware failure while processing a query, partial rows processed by the database and returned to the client would be lost.
You can choose how you want the driver to behave if exceptions occur during failover by setting the FailoverGranularity connection property. If an exception occurs while the driver is reestablishing a lost connection, the driver can react in either of the following ways:
It can fail the entire failover process. The driver stops trying to connect to an alternative server and returns an exception indicating that the connection was lost.
It can proceed with the failover process as far as it is able. For example, suppose an exception occurred while reestablishing the connection because the driver was unable to log the user into the database. In this case, you may want the driver to notify your application of the exception and proceed with the failover process.
During the failover process, your application may experience a short pause while the driver establishes a new connection or reestablishes a lost connection on an alternate server. If your application is time-sensitive (a real-time customer order application, for example) and cannot absorb this wait, you can set the FailoverPreconnect property to true. Setting the FailoverPreconnect property to true instructs the driver to establish connections to the primary server and an alternate server at the same time. Your application uses the first connection that is successfully established. As a bonus, if this connection to the database is lost at a later time, the driver saves time in reestablishing the connection on the server it fails over to because it can use the spare connection in its failover process.