Using failover in a high-availability system

A high availability cluster includes two or more machines that are configured so that if one machine (or application) is brought down, the second machine assumes the workload of both machines. Each of these machines is called one node of the high availability cluster. A high availability cluster is typically used in an environment that must always be available, for example, a banking system to which clients must connect continuously, 365 days a year.

Failover enables Adaptive Server to work in a high availability cluster in an active-active or active-passive configuration.

During failover, clients connected to the primary companion using the failover property automatically reestablish their network connections to the secondary companion. Failover can be enabled by setting the connection property HASession to “1” (default value is “0”). If this property is not set, the session failover does not occur even if the server is configured for failover. You must also set the SecondaryServer and SecondaryPort properties.

See the ASE document, Using Sybase Failover in a High Availability System, for information about configuring your system for high availability.

If failover happens within a transaction, only changes that were committed to the database before failover are retained. When a failover occurs, the Provider tries to reconnect to the secondary server. If a connection to the secondary server is established, ADO.NET Data Provider throws an AseFailoverException with a message that failover has occurred. Then, the client must reapply the failed transaction with the new connection. If the connection to the secondary server is not established, a regular AseException is raised in ADO.NET Data Provider with a message that the connection has been lost. For example:

AseConnection.ConnectionString =
   ”Data Source='tpsun1';" +
   "Port = 5000;" +
   "Database=pubs2;" +
   "User ID=sa;" +
   "Password=sapass;" +
   "HASession=1;" +
   "Secondary Data Source='tpsun2';" +
   "Secondary Server Port=5000";

The following code shows how to catch AseFailoverException:

....
Open connection
...more code

try
{   using (AseDataReader rdr =
   selectCmd.ExecuteReader())
   {
   ....
   }
}
catch (AseFailoverException)
{
   //Make sure that you catch AseFailoverException
   //before AseException as AseFailoverException is
   //derived from AseException

   //HA has occured. The application has successfully    //connected to the secondary server. All uncommitted    //transactions have been rolled back.

   //You could retry your transactions or prompt user    //for a retry operation
}
catch (AseException)
{
//Either some other problem or the Failover did not //successfully connect to the secondary server. Apps. //should react accordingly
}