Network Deployment (Distributed operating systems), v8.0 > Scripting the application serving environment (wsadmin) > Scripting for data access resources > Configure data access with wsadmin scripting
Test data source connections using wsadmin.sh
We can test connections for data sources with the wsadmin tool and scripting. After we 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.
We can use the testConnection command for the AdminControl object to test data source connections for a cell, node, server, application, or cluster scope. This topic provides an example that tests the data source connection for the application scope.
Procedure
- Test the data source connection for a cell, node, or server scope.
- Start wsadmin.sh.
- 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 wsadmin.sh.
- 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 wsadmin.sh.
- 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.
Test a connection with the administrative console
Use the wsadmin scripting AdminControl object for scripted administration
Related
Data source settings
Commands for the AdminControl object using wsadmin.sh