Testing data source connections using wsadmin scripting

You can test connections for data sources with the wsadmin tool and scripting. After you have defined and saved a data source, you can test the data source connection to ensure that the parameters in the data source definition are correct.

About this task

You can use the testConnection command for the AdminControl object to test data source connections for a cell, node, server, application, or cluster scope. Use the example to test the data source connection for the application scope.

Procedure

  • Test the data source connection for a cell, node, or server scope.
    1. Start the wsadmin scripting tool.
    2. Identify the DataSourceCfgHelper MBean and assign it to the dshelper variable.
      • Using Jacl:
        set ds [$AdminConfig getid /DataSource:DS1/]
        $AdminControl testConnection $ds
      • Using Jython:
        ds = AdminConfig.getid('/DataSource:DS1/')
        AdminControl.testConnection(ds)

      Examples of output:

      WASX7217I: Connection to provided datasource was successful.
      DSRA0174W: Warning: GenericDataStoreHelper is being used.
      WASX7015E: Exception running command: "$AdminControl testConnection    
      $ds1"; exception information:                                          
       com.ibm.websphere.management.exception.AdminException                 
      javax.management.MBeanException                                        
      java.sql.SQLRecoverableException: java.sql.SQLRecoverableException: Io 
      exception: The Network Adapter could not establish the                 
      connectionDSRA0010E: SQL State = 08006, Error Code = 17,002 
    3. Test the connection using testConnectionToDataSource.

      The following example invokes the testConnectionToDataSource operation on the MBean, passing in the classname, userid, password, database name, JDBC driver class path, language, and country.

      • Using Jacl:
        $AdminControl invoke $dshelper testConnectionToDataSource 
        "COM.ibm.db2.jdbc.DB2XADataSource db2admin db2admin 
        {{databaseName sample}} /sqllib/java/db2java.zip en US"
      • Using Jython:
        print AdminControl.invoke(dshelper, 'testConnectionToDataSource',  
        'COM.ibm.db2.jdbc.DB2XADataSource dbuser1 dbpwd1 
        "{{databaseName jtest1}}" /sqllib/java12/db \"\" \"\"')

        Example output:

        WASX7217I: Connection to provided data source was successful.
  • Test the data source connection for an application scope.
    1. Start the wsadmin scripting tool.
    2. Get the data source for the application of interest.
      Use the AdminConfig object to determine the configuration IDs of the myApplication application and DSA1 data source, as the following examples demonstrate:
      • Using Jacl:
        set appID [$AdminConfig getid /Deployment:myApplication/]
        set ds [$AdminConfig list DataSource $appID]
      • Using Jython:
        appID = AdminConfig.getid("/Deployment:myApplication/")
        ds = AdminConfig.list("DataSource", appID)
    3. Test the connection using testConnection.
      Use the AdminConfig object to test the connection for the data source of interest, as the following examples demonstrate:
      • Using Jacl:
        $AdminControl testConnection $ds
      • Using Jython:
        AdminControl.testConnection(ds)
    The command returns output that indicates whether the connection is successful, as demonstrated in the following sample output:
    WASX7467I: Connection to provided datasource on node myNode processnodeagent was successful.
    WASX7217I: Connection to provided datasource was successful.
  • Test the data source connection for a cluster scope.

    In the following example, the Cluster1 server cluster contains cluster members on the node1, node2, and node3 nodes. The Cluster1 server cluster contains the DSC1 data source.

    1. Start the wsadmin scripting tool.
    2. Get the data source configuration ID for the cluster of interest.
      Use the AdminConfig object to determine the configuration IDs of the Cluster1 cluster and DSA1 data source, as the following examples demonstrate:
      • Using Jacl:
        set cluster [$AdminConfig getid /ServerCluster:Cluster1/]
        set ds [$AdminConfig list DataSource $cluster]
      • Using Jython:
        cluster = AdminConfig.getid("/ServerCluster:Cluster1/")
        ds = AdminConfig.list("DataSource", cluster)
    3. Test the connection.
      Use the AdminConfig object to test the connection for the data source of interest, as the following examples demonstrate:
      • Using Jacl:
        $AdminControl testConnection $ds
      • Using Jython:
        AdminControl.testConnection(ds)
    The command returns output that indicates whether the connection is successful, as demonstrated in the following sample output:
    WASX7467I: Connection to provided datasource on node node1 process nodeagent was successful.
    WASX7467I: Connection to provided datasource on node node2 process nodeagent was successful.
    WASX7467I: Connection to provided datasource on node node3 process nodeagent was successful.
    WASX7217I: Connection to provided datasource was successful.