asawyer
asawyer

Reputation: 17808

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.

Upvotes: 3

Views: 4348

Answers (4)

dario_ramos
dario_ramos

Reputation: 7309

In my case, I was getting this error because my password had expired and I changed it, but I forgot to update my connection strings in my .config files. Therefore, my user was disabled after three (programmatic) attempts to login with the old password.

I realized this when I tried to acess the server using Query Tool and it told me my user was disabled even though I entered the new password. It was my bad, but the error message was not really informative...

Upvotes: 0

asawyer
asawyer

Reputation: 17808

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.

Upvotes: 3

A very common scenario is TCP/IP connections are silently shutdown by network routers and firewalls when being idle for a long time.

I would guess that this is exactly what happens here.

Upvotes: 1

Mike Wills
Mike Wills

Reputation: 21275

Hmmm... that is a weird one. Have you been able to duplicate the error? If you don't get any other suggestions here, maybe try putting this on one of the midrange.com lists. I would try MIDRANGE-L or System i dotNet.

Upvotes: 0

Related Questions