3 Advanced Features : Using Connection Failover

Using Connection Failover
Connection failover provides failover protection for new connections only. The data provider fails over new connections to an alternate, or backup, database server if the primary database is unavailable, for example, because of a hardware failure or traffic overload. Alternate servers are tried until a connection is successfully established or until all database servers (primary and alternate) have been tried a specified number of times. If a connection to the database is lost, or dropped, the data provider does not fail over the connection.
For example, as shown in Figure 3-1, Database Server A is designated as the primary database server, Database Server B is the first alternate server, and Database Server C is the second alternate server.
Figure 3-1. Connection FailoverThe application can connect to three database servers. Connection failover is enabled, and the application first tries to connect to Database Server A, then Database Server B, and then Database Server C.
 
First, the data provider attempts to connect to the primary database, Database Server A (1). If connection failover is enabled and Database Server A fails to accept the connection, the data provider attempts to connect to Database Server B (2). If that connection attempt also fails, the data provider attempts to connect to Database Server C (3).
In this scenario, it is probable that at least one connection attempt would succeed, but if no connection attempt succeeds, the data provider can retry the primary server and each alternate database for a specified number of attempts. You can specify the number of attempts that are made through the connection retry feature. You can also specify the number of seconds of delay, if any, between attempts through the connection delay feature. See “Using Connection Retry” for more information about connection retry.
The data provider fails over to the next alternate server only if a successful connection cannot be established with the current alternate server. If the data provider successfully establishes communication with a database and the database rejects the connection request because, for example, the login information is invalid, then the data provider generates an exception and does not try to connect to the next database in the list.
Guidelines for Primary and Alternate Servers
Many databases provide advanced database replication technologies such as DB2 High Availability Disaster Recovery (HADR), Oracle Real Application Clusters (RAC), and Microsoft Cluster Server (MSCS). The failover functionality provided by the data providers does not require any of these technologies, but can work with them to provide comprehensive failover protection. Use the following guidelines for primary and alternate servers to ensure that failover works correctly in your environment:
SQLServerConnection Conn = new SQLServerConnection();
Conn = new SQLServerConnection("Host=Accounting1;Port=1433;
Database Name=TEST;User ID=mike;Password=bogey;
Alternate Servers="Host=Accounting1;Port=1433;Database Name=TEST");