Avatar of jbaird123
jbaird123
 asked on

AS400 - How to test for connectivity

I have a Java program that interacts with an AS400 database.  I am trying to code a work-around for a connectivity problem I am facing.  Sometimes for various reason, after I establish a connection to the database, the connection will be lost (idle timeout, loss of network connection, etc.).  In those cases, I need to be able to check whether the connection is still active, and if not, then I need to re-connect.  In order to test for connectivity, I would like to simply execute some generic SQL statement and check whether it was successful.  Is there any kind of generic "dummy" SQL statement or command that can be run on any AS400 system which will allow me to know whether the connection object is still valid or now?

For example, here is how I do this same operation using both Oracle and MSSQL:

Oracle:   "select 'success' from dual"
MSSQL:  "select 'success'"

Both of those statements work fine for Oracle and MSSQL.  I am looking for something roughly equivalent on the AS400.

Thanks.
IBM System i

Avatar of undefined
Last Comment
Gary Patterson, CISSP

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Member_2_2484401

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jbaird123

ASKER
Perfect!  Thanks!
Gary Patterson, CISSP

How long is the period of time before you experience a connection drop?  Usually this is due to an intermediate firewall, though there is an IBM i TCP connection timer that will eventually drop a connection due to inactivity.  This is a system-wide setting.

Check your firewall log (may need to enable logging of inactive session timeout events), and the QTCP message queue on the IBM i for relevant messages.

Sometimes you can fix this by specifying a longer timeout on the host or firewall.

If you are writing the application, you could just run a small request like the one above just frequently enough to keep the connection "alive" - provided you can determine the idle timeout period.

Also, you can look at the connection in NETSTAT, option 3 on the iSeries and watch the change in status as the connection gets older and older.

This is a common issue, and it can be tricky to resolve unless you are the programmer writing the application - then you can include some sort of (I suggest configurable, since the value could change at the whim of a network admin) keepalive timer.
jbaird123

ASKER
Gary,

Thanks for the info.  I am essentially working on the keep alive timer that you suggest.  I have a situation where a connection is established and then sits idle for a couple of hours while an unrelated process completes.  The issue is that the unrelated process could take anywhere from a couple of seconds to several hours (and there is no way to know in advance how long it will take), and since this connection is used prior to this unrelated process, I cannot wait until after the process is complete to establish the connection.  I basically just need to check whether it is still active after sitting idle for so long and if not, then establish a new connection, otherwise, use the old connection.

Thanks.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Gary Patterson, CISSP

Here is my suggestion:

1) Connect
2) Submit job
3) Disconnect
3) Set up some sort of notification mechanism in job - put a message on a data queue when it it done (IBM has PC data queue APIs for Java, legacy Windows (C/VB), and .NET).  Even better, just send a little text file via FTP to the client system
4) Watch for the notification event, and reconnect and move on - no overhead on the host, and easy to implement.