Search code examples
pythondatabasedb2odbcdb2-luw

Custom python application name in db2 list application output


Connect to db2 with python ibm_db_dbi and get the list of applicationsn NAME column always shows python.

import ibm_db_dbi
db2ConnArgs = "DATABASE=%s;HOSTNAME=%s;PORT=%s;PROTOCOL=TCPIP;UID=%s;PWD=%s;" % ('SAMPLE', 'localhost', 50000, 'db2test', 'db2test')
db2ConnDict = {ibm_db_dbi.SQL_ATTR_CURRENT_SCHEMA:'SAMPLE'}
dbhandle = ibm_db_dbi.connect(db2ConnArgs,"", "","","",db2ConnDict)

Run db2 list application

Auth Id  Application    Appl.      Application Id                                                 DB       # of
        Name           Handle                                                                    Name    Agents
-------- -------------- ---------- -------------------------------------------------------------- -------- -----
DB2TEST  python         47         127.0.0.1.34218.180529224354                                   SAMPLE   1

Is it possible to assign a custom name?


Solution

  • It's possible using ibm_db_dbi.ibm_db.SQL_ATTR_INFO_PROGRAMNAME connection attribute

    import ibm_db_dbi
    db2ConnArgs = "DATABASE=%s;HOSTNAME=%s;PORT=%s;PROTOCOL=TCPIP;UID=%s;PWD=%s;" % ('SAMPLE', 'localhost', 50000, 'db2test', 'db2test')
    db2ConnDict = {ibm_db_dbi.SQL_ATTR_CURRENT_SCHEMA:'SAMPLE', ibm_db_dbi.ibm_db.SQL_ATTR_INFO_PROGRAMNAME : 'luis_app'}
    dbhandle = ibm_db_dbi.connect(db2ConnArgs,"", "","","",db2ConnDict)
    

    Run db2 list application

    Auth Id  Application    Appl.      Application Id                                                 DB       # of
            Name           Handle                                                                    Name    Agents
    -------- -------------- ---------- -------------------------------------------------------------- -------- -----
    DB2TEST  luis_app       31         127.0.0.1.34194.180529223939                                   SAMPLE   1
    

    Original bug report: https://github.com/ibmdb/python-ibmdb/issues/144