For up-to-date product documentation, see the IBM MobileFirst Foundation Developer Center.


Configure DB2 HADR seamless failover for MobileFirst Server and Application Center data sources

You must enable the seamless failover feature with WebSphere® Application Server Liberty profile and WebSphere Application Server. With this feature, we can manage an exception when a database fails over and gets rerouted by the DB2® JDBC driver.

Note: DB2 HADR failover is not supported for Apache Tomcat.

By default with DB2 HADR, when the DB2 JDBC driver performs a client reroute after detecting that a database failed over during the first attempt to reuse an existing connection, the driver triggers com.ibm.db2.jcc.am.ClientRerouteException, with ERRORCODE=-4498 and SQLSTATE=08506. WebSphere Application Server maps this exception to com.ibm.websphere.ce.cm.StaleConnectionException before it is received by the application.

In this case, the application would have to catch the exception and execute again the transaction. The MobileFirst and Application Center runtime environments do not manage the exception but rely on a feature that is called seamless failover. To enable this feature, we must set the enableSeamlessFailover JDBC property to "1".


WebSphere Application Server Liberty profile configuration

You must edit the server.xml file, and add the enableSeamlessFailover property to the properties.db2.jcc element of the MobileFirst and Application Center data sources. For example:

<dataSource jndiName="jdbc/WorklightAdminDS" transactional="false"> <jdbcDriver libraryRef="DB2Lib"/> <properties.db2.jcc databaseName="WLADMIN" currentSchema="WLADMSC" serverName="db2server" portNumber="50000" enableSeamlessFailover= "1" user="worklight" password="worklight"/> </dataSource>


WebSphere Application Server configuration

From the WebSphere Application Server administrative console for each MobileFirst and Application Center data source:

  1. Go to Resources > JDBC > Data sources > DataSource name.
  2. Select New and add the following custom property, or update the values if the properties already exist:

    enableSeamlessFailover : 1

  3. Click Apply.
  4. Save your configuration.

For more information about how to configure a connection to an HADR-enabled DB2 database, see Setting up a connection to an HADR-enabled DB2 database.

Parent topic: Configuring data sources