Search code examples
ibm-midrange

Why am I getting a "A communication error occurred" querying an as/400 server?


I have a site that queries an as/400 database for certain peices of information, including one small peice of info on the logged in user.

Because of this, the as/400 is queried whenever a user is logged to a fresh session.

I'm getting sporadic reports of a A communication error occurred server error, especially when people login on the weekends.

If you hit f5 and refresh the page the error clears and everything works great.

Does anyone know why I am getting this error?

I was thinking that since f5 clears the error that I could simply retry any query that failed for this reason, but I don't want to start without a deeper understanding of the situation.

I've gone through IBM's user docs and quite of bit of google searching and haven't come up with anything.

edit

The connection is made with the IBM.Data.DB2.iSeries drivers for windows, version 12.

The connection code looks something like:

public DataSet RetrieveDataSet(string sql)
 {
    DataSet ds = new DataSet();
    iDB2Connection con = new iDB2Connection();

    iDB2DataAdapter da = null;
    try
    {
        con.ConnectionString = ConnectionString;

        con.Open();

        da = new iDB2DataAdapter(sql, con);

        da.Fill(ds);

    }
    catch (Exception ex)//yes i am aware this should not be catching the base exception
    {
        LogError("AS400Connection", "RetrieveAll", ex.Message, sql, ex.StackTrace, con.JobName.Trim());
        throw;
    }
    finally
    {
        if (con.State == ConnectionState.Open)
            con.Close();
        if(da!=null)
            da.Dispose();
        con.Dispose();
        ds.Dispose();
    }

    return ds;
}

The da.Fill(...) line is throwing the Communication Error exception.


Solution

  • I ended up just writing a small peice of code that attemped a small query just before each critical section, so if the job was ended it only kills that query instead of the whole app.

    Edit -

    The "CheckConnectionOnOpen" connection string parameter does essential the same thing, but as part of the driver.