title: Why am I getting a "A communication error occurred" querying an as/400 server?
body: <p>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.</p>
  
  <p>Because of this, the as/400 is queried whenever a user is logged to a fresh session.</p>
  
  <p>I'm getting sporadic reports of a <code>A communication error occurred</code> server error, especially when people login on the weekends.</p>
  
  <p>If you hit f5 and refresh the page the error clears and everything works great.</p>
  
  <p>Does anyone know why I am getting this error?</p>
  
  <p>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.</p>
  
  <p>I've gone through IBM's user docs and quite of bit of google searching and haven't come up with anything.</p>
  
  <p><em>edit</em> </p>
  
  <p>The connection is made with the <code>IBM.Data.DB2.iSeries</code> drivers for windows, version 12.</p>
  
  <p>The connection code looks something like:</p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p>The <code>da.Fill(...)</code> line is throwing the Communication Error exception.</p>