Example of enabling Informix high availability support in non-Java clients

Before you can use Informix high availability support in CLI, .NET, or embedded SQL applications that connect directly to Informix database server, you need to update the db2dsdriver configuration file with the appropriate settings, and connect to a Connection Manager.

The following example demonstrates setting up a CLI client to take advantage of Informix high availability support with one Connection Manager.

Before you can set up the client, you need to configure one or more high availability clusters that are controlled by Connection Managers.

Follow these steps to set up the client:

  1. Create a db2dsdriver.cfg file with the basic settings for Informix high availability support. When you set enableWLB to true, you enable workload balancing and automatic client reroute capability.
    <configuration>
      <dsncollection>
        <dsn alias="IDSCM1" name="IDSCM1" host="ids.cm1.ibm.com" port="446">
        </dsn>
      </dsncollection>
      <databases>
        <database name="IDSCM1" host="ids.cm1.ibm.com" port="446">
           <!-- database-specific parameters -->
           <wlb>
              <!-- Enable workload balancing to get
              automatic client reroute
              functionality -->
              <parameter name="enableWLB" value="true" />
              <!-- maxTransports represents the maximum number of transports -->
              <parameter name="maxTransports" value="80" />
           </wlb>
        </database>
      </databases>
      <parameters>
        <parameter name="connectionLevelLoadBalancing" value="true"/>
      </parameters>
    </configuration>
  2. Suppose that the DSN definition for IDSCM1 provides connectivity information for a Connection Manager for database IDSCM1. In a CLI application, use code like this to connect to the Connection Manager:
    …
       SQLHDBC         hDbc    = SQL_NULL_HDBC;
       SQLRETURN       rc      = SQL_SUCCESS;
       SQLINTEGER      RETCODE = 0;
       char            *ConnStrIn =
                       "DSN=IDSCM1;PWD=mypass";
                    /* dsn matches the database name in the configuration file */
       char            ConnStrOut [200];
       SQLSMALLINT     cbConnStrOut;
       int             i;
       char            *token;
    …
      /*****************************************************************/
      /* Invoke SQLDriverConnect                                       */
      /*****************************************************************/
       RETCODE = SQLDriverConnect (hDbc                 ,
                                   NULL                 ,
                                   (SQLCHAR *)ConnStrIn ,
                                   strlen(ConnStrIn)    ,
                                   (SQLCHAR *)ConnStrOut,
                                   sizeof(ConnStrOut)   ,
                                   &cbConnStrOut        ,
                                   SQL_DRIVER_NOPROMPT);
    …