title: Sql error "Arithmetic operation resulted in an overflow."
body: <p>I am running a service that does some computation and communicates with an ms sql server every minute or so (24/7, uptime is very important) and writes to error log if anything funny happens (like a timeout or lost connection).</p>
  
  <p>This works great, however once in a while I will get this error:</p>
  
  <blockquote>
    <p>Arithmetic operation resulted in an overflow.</p>
  </blockquote>
  
  <p>Since this is run on client's side, and the exception has only occurred 3 times since the project has been launched (a couple of months now) this would be extremely hard to catch and debug. </p>
  
  <p>I am using OleDbDataAdapter to communicate with the server. The data being received from the server was not special in any way, that I am aware of at least! Data should never exceed field sizes etc, so I can't really think of a reason for this error to occur. Again this is extremly hard to verify since I all I get is the error message.</p>
  
  <p>My question is: Why does this error usually accrue? I have been unable to find any real information about it on the web, so if someone could supply me with some information, that would be very much appreciated.</p>
  
  <p>Thank you!</p>
  
  <p><strong>EDIT</strong>: A careful read through the error report showed me that this error has actually occurred during the Fill of DataTable object. Code looks something like this:</p>
  
  <pre><code>DataTable.Clear();
  try
  {
      oledbdataAdapter.Fill(DataTable, sqlString);
  }
   catch (Exception e)
  {
      //error has occured, report
  }
  </code></pre>
  
  <p>Can anyone make sense of this?</p>
  
  <p><strong>EDIT2</strong>: I have just thought of this ... Is it possible this exception would be thrown because the system doesn't have enough system resources to complete the Fill? This is the only reason I can think of that would explain the exception occurring. It would also explain why it only occurs on some servers and never occurs on dev server ...</p>
  
  <p><strong>EDIT3</strong>: Here is the whole exception in case it gives anyone any more insight:</p>
  
  <pre><code>System.OverflowException: Arithmetic operation resulted in an overflow.
     at System.Data.DataTable.InsertRow(DataRow row, Int32 proposedID, Int32 pos, Boolean fireEvent)
     at System.Data.DataTable.LoadDataRow(Object[] values, Boolean fAcceptChanges)
     at System.Data.ProviderBase.SchemaMapping.LoadDataRow()
     at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
     at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
     at System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
     at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
     at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
     at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
     at INDAZajemService.INDAZajem.FillDataSet()
  </code></pre>