Testing data source connections using scripting
We can test connections for data sources with wsadmin and scripting. After we have defined and saved a data source, we can test the data source connection to verify the parameters in the data source definition are correct.
Use the testConnection command for AdminControl to test data source connections for a cell, node, server, application, or cluster scope. This page provides an example that tests the data source connection for the application scope.
- Test the data source connection for a cell, node, or server scope.
- Launch the wsadmin scripting tool using the Jython scripting language.
- 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)For example...
WASX7217I: Connection to provided datasource was successful.
- Test the connection.
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}} c:/sqllib/java/db2java.zip en US"- Jython...
print AdminControl.invoke(dshelper, 'testConnectionToDataSource', 'COM.ibm.db2.jdbc.DB2XADataSource dbuser1 dbpwd1 "{{databaseName jtest1}}" c:/sqllib/java12/db \"\" \"\"')Example output:
WASX7217I: Connection to provided data source was successful.
- Test the data source connection for an application scope.
- Launch the wsadmin scripting tool using the Jython scripting language.
- 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. 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.
- Launch the wsadmin scripting tool using the Jython scripting language.
- 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
Testing a connection with the admin console
Use AdminControl for scripted administration
Related
Data source settings
Example: Testing a connection using testConnection(ConfigID)
Commands for AdminControl