Topic
  • 1 reply
  • Latest Post - ‏2010-12-29T09:27:46Z by SystemAdmin
BillRose
BillRose
1 Post

Pinned topic Database Failover Question

‏2010-12-21T02:59:28Z |
We are using a SQL Server database and using MS driver for SQL Server.

The database connection is done by the following code

In the EJB Deployment Descriptor, we have the following code for database connectivity

<resource-ref id="ResourceRef_1218093177156">
<description>JDBC DataSource</description>
<res-ref-name>jdbc/dsDBRef</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
public final static String jndiDSName="java:comp/env/jdbc/dsDBRef";

dataSource = (DataSource)ServiceLocator.getDataSource(jndiDSName);
connection = dataSource.getConnection();

The connection is working perfectly fine.
We want to do a database failover for the application.
If the primary database fails, we would need to connect to a different machine and use that database.

Can anyone give some specific information on to how to acheive this.
Updated on 2010-12-29T09:27:46Z at 2010-12-29T09:27:46Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    4447 Posts

    Re: Database Failover Question

    ‏2010-12-29T09:27:46Z  
    just a thought :

    create a second datasource.

    then :
    try {
    dataSource = (DataSource)ServiceLocator.getDataSource(jndiDSName);
    connection = dataSource.getConnection();
    }catch (XYZException e) { // naming, sql, etc.
    dataSource2 = (DataSource) ServiceLocator.getDataSource(jndiDSName2);
    connection = dataSource2.getConnection();
    }