+

Search Tips   |   Advanced Search

 

Test connection service

 

WAS provides a test connection service for validating data source configurations. The testConnection operation instantiates the data source configuration, gets a connection, and then immediately closes the connection.

If the definition of your data source includes a WebSphere variable, determine how your scope settings for both the variable and data source can affect the test connection results. Your next step is to choose which of the three ways you want to activate the test connection service: through the console, the wsadmin tool, or a Java stand-alone program.

 

Verifying your scope settings

Associating WebSphere variables with your data source configurations can elicit test connection results that are incongruent with the run-time behavior of your application. In some cases, a test connection operation fails, but the physical data source functions normally during application runtime. The cause of the potential conflict is the difference between how your appserver handles the scope settings of WebSphere variables at runtime, and how it handles those same scope settings for a test connection operation. Understanding the difference helps you create successful data source configurations. At runtime, WAS invokes a physical data source by resolving the appropriate variable at a level where one of the following criteria exists:

Application Server meets these conditions by attempting to resolve the variable at each level of the scope spectrum. That is, the product tries to resolve the variable in the server scope, then the cluster scope, then the node scope, and lastly the cell scope. However, Application Server tests connections at one scope only; it performs the test operation in the JVM of the same scope as that of the data source configuration. WAS attempts to resolve the driver class path variable at that scope only.

Table 1. Correlation of data source scope with the test connection JVM
Data source scope JVM where the test connection operation occurs
Cell Deployment manager process
Node Node agent process (of the relevant node)
Cluster Node agent for each node that contains a cluster member
Server Server; if the server is unavailable, the test connection operation is retried in the node agent for the node that contains the appserver.

If the scope of the WebSphere variable is smaller than that of the data source, the test connection operation fails. The following table shows the scenarios that produce this failure, as well as those that produce success.

Table 2. Test connection results for different data source and WebSphere variable combinations
Data source scope Cell level variables Node level variables Server level variables
Cell level Ok Fail Fail
Node level Ok Ok Fail
Server level Ok Ok Ok

Contrary to expectations, these test connection failures generally do not translate into run-time failures. Ensure that the location of your JDBC driver files is accessible to every client that must use the data source, and configure your WebSphere variable with the full path of that location.

Test connection success, but run-time failure

However, one of the scope combinations listed in Table 2 can produce the reverse scenario: the test connection operation succeeds, but the data source fails at runtime. This anomaly occurs in the case of a cell-scoped data source that uses a cell-scoped WebSphere variable. The connection test is successful because the operation takes place in the deployment manager process (as indicated in Table 1), where Application Server can resolve the cell-scoped variable. That data source can fail at runtime because the cell-scoped variable might be overridden with a null value.

When you create a node, Application Server creates environment variables for all supported JDBC drivers at the node scope, and initializes each variable with an empty string. Because an appserver attempts to resolve variables from the low end of the scope spectrum to the high end, the node scope variable overrides the cell scope variable at runtime. The server reads the empty string and accepts it as the JDBC driver class path. The null class path elicits a classNotFound exception when the server attempts to use the data source.

Using either one of the Application Server administrative options, you can prevent the empty string from becoming the final value for the driver class path variable.

Use cell scope resources only if all nodes that need access to the data source, including the deployment manager node, run on the same platform and have the JDBC drivers installed in the same location. Otherwise, use the node scope as the largest scope setting for your data sources.

Bypassing variable lookups

You can bypass the environment variable lookups by changing the class path entries for the JDBC provider to hard-coded values. However, this strategy succeeds only if you configure the class path identically on all nodes where the data source must function.

 

Activating the test connection service

There are three ways to activate the test connection service: through the administrative console, the wsadmin tool, or a Java stand-alone program. Each process invokes the same methods on the same MBean.

Administrative console

WebSphere Application Server allows you to test a connection from the administrative console by simply pushing a button: the Data source collection, Data source settings, V4 data source collection, and Version 4 data source settings pages all have Test Connection buttons. After you define and save a data source, you can click this button to ensure that the parameters in the data source definition are correct. On the collection page, you can select several data sources and test them all at once. Note that there are certain conditions that must be met first. For more information, see Testing a connection with the administrative console.

The following exception occurs when you click Test Connection to connect a Sybase data source from the administrative console.

Test connection failed for data source isagent on server server1 at node  svtaix24Node01 with the following exception: java.lang.Exception:  java.sql.SQLException: JZ006: Caught IOException: java.net.ConnectException: A  remote host refused an attempted connect operation.DSRA0010E: SQL State = JZ006, 
Error Code = 0
This exception occurs when the Sybase data source port number is not matched to the port configured in Sybase server. The default port number is 5000. Check the port number of your Sybase server in the interfaces file under /<sybase install directory>.

WsAdmin tool

The wsadmin tool provides a scripting interface to a full range of WAS administration activities. Because the Test Connection functionality is implemented as a method on an MBean, and wsadmin can invoke MBean methods, wsadmin can be utilized to test connections to data sources. You have two options for testing a data source connection through wsadmin:

The AdminControl object of wsadmin has a testConnection operation that tests the configuration properties of a data source object. For information, see Testing a connection using wsadmin.

You can also test a connection by invoking the MBean operation. Use Example: Testing data source connection using wsadmin as a guide for this technique.

Java stand-alone program

Finally, you can test a connection by executing the testConnection() method on the DataSourceCfgHelper MBean. This method allows you to pass the configuration ID of the configured data source. The Java program connects to a running Java Management Extensions (JMX) server to access the MBean. In a ND installation of Application Server, you connect to the JMX server running in the deployment manager, usually running on port 8879.

The return value from this invocation is either 0, a positive number, or an exception. 0 indicates that the operation completed successfully, with no warnings. A positive number indicates that the operation completed successfully, with the number of warnings. An exception indicates that the test of the connection failed.

You can find an example of this code in Example: Test a connection using testConnection(ConfigID).


 

Related concepts


Variables

 

Related tasks


Configure WebSphere variables
Testing a connection with the console
Testing a connection using wsadmin

 

Related Reference


Administrative console scope settings
Example: Testing a connection using testConnection(ConfigID)