Test data source connections
We can test connections for data sources with wsadmin.sh and scripting. After we have defined and saved a data source, we can test the data source connection to ensure that the parameters in the data source definition are correct.
We 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.
- Test the data source connection for a cell, node, or server scope.
- Start the wsadmin scripting tool.
- Identify the DataSourceCfgHelper MBean and assign it to the dshelper variable.
- Jacl:
set ds [$AdminConfig getid /DataSource:DS1/] $AdminControl testConnection $ds
- 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
- 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.
- Jacl:
$AdminControl invoke $dshelper testConnectionToDataSource "COM.ibm.db2.jdbc.DB2XADataSource db2admin db2admin {{databaseName sample}} /sqllib/java/db2java.zip en US"
- 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.
- Start the wsadmin scripting tool.
- 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:
- Jacl:
set appID [$AdminConfig getid /Deployment:myApplication/] set ds [$AdminConfig list DataSource $appID]
- Jython:
appID = AdminConfig.getid("/Deployment:myApplication/") ds = AdminConfig.list("DataSource", appID)
- Test the connection using testConnection.
Use the AdminConfig object to test the connection for the data source of interest, as the following examples demonstrate:
- Jacl:
$AdminControl testConnection $ds
- 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.
- Start the wsadmin scripting tool.
- 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:
- Jacl:
set cluster [$AdminConfig getid /ServerCluster:Cluster1/] set ds [$AdminConfig list DataSource $cluster]
- Jython:
cluster = AdminConfig.getid("/ServerCluster:Cluster1/") ds = AdminConfig.list("DataSource", cluster)
- Test the connection.
Use the AdminConfig object to test the connection for the data source of interest, as the following examples demonstrate:
- Jacl:
$AdminControl testConnection $ds
- 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.
Related tasks
Test a connection with the administrative console Use the wsadmin scripting AdminControl object for scripted administration
Data source settings Commands for the AdminControl object