Sql error "Arithmetic operation resulted in an overflow."

David Božjak picture David Božjak · Jul 16, 2009 · Viewed 19.5k times · Source

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).

This works great, however once in a while I will get this error:

Arithmetic operation resulted in an overflow.

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.

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.

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.

Thank you!

EDIT: 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:

DataTable.Clear();
try
{
    oledbdataAdapter.Fill(DataTable, sqlString);
}
 catch (Exception e)
{
    //error has occured, report
}

Can anyone make sense of this?

EDIT2: 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 ...

EDIT3: Here is the whole exception in case it gives anyone any more insight:

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()

Answer

Lima picture Lima · Jul 16, 2009

If you are doing calculations on aggregations on the data then it would appear to be resulting in bigger results then the table structure is expecting.