DB2 allows client applications to set the application name using the SQL_ATTR_INFO_PROGRAMNAME attribute. If you have a number of perl applications connecting to the same database, this allows you to distinguish between them by setting the application name to the script / library name instead of the default "perl". The application name set is visible when an administrator performs "list applications".

I have long wanted to do this from DBD::DB2. I asked IBM to add this to the driver and received an internal defect number for this (166029); however, the latest DBD::DB2 release (1.3) does not include this feature.

The attached patch shows how this feature can be added. I hope IBM gets around to including this in the next DBD::DB2 release; in the meantime, other users of DBD::DB2 may benefit from this change.

This feature is used as follows:

  my $dbh = DBI->connect("dbi:DB2:$dsn", $userid, $password,
                         { 'db2_application_name' => $name });

Cheers,
  Hildo Biersma
*** dbdimp.c.orig       Tue Dec 30 10:03:29 2008
--- dbdimp.c    Tue Dec 30 10:02:58 2008
***************
*** 417,422 ****
--- 417,440 ----
        if( SQL_SUCCESS != ret )
          goto exit;
      }
+ 
+     pval = hv_fetch( attrh, "db2_application_name", 20, 0 );
+     if(pval && SvOK(*pval)) {
+         STRLEN vl;
+       SQLPOINTER app_name;
+       SQLINTEGER app_name_len;
+ 
+         app_name = (SQLPOINTER)SvPV(*pval, vl);
+         app_name_len = (SQLINTEGER)vl;
+ 
+       ret = SQLSetConnectAttr(imp_dbh->hdbc,
+                               SQL_ATTR_INFO_PROGRAMNAME,
+                               app_name, 
+                               app_name_len);
+       ret = check_error( dbh, ret, "Set application name failed" );
+       if( SQL_SUCCESS != ret )
+           goto exit;
+     }
    }
  
    /* If the string contains a =, use SQLDriverConnect */

Reply via email to