Sql error "Arithmetic operation resulted in an overflow."

20,645

Solution 1

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.

Solution 2

I solved the problem when I was using VS.Net 2013 with SQL Server as backend. Just set the project build settings to "x86" instead of "Any cpu". and there you go. But of-course you need to check your requirements first.

Solution 3

I had this issue, but only when connecting from a web application running under IIS. The solution in my case was:

  1. Open IIS
  2. Browse to the application pool used by my application
  3. Click "Advanced Settings"
  4. Change the option "Enable 32-Bit Applications" to "True"
  5. Click "OK"

I didn't even have to restart the application pool, the change fixed the problem immediately.

Solution 4

It usually happens when you have a number that is too big or too small to fit into a certain data type. So if you had, say, the number 120398018209571037 and tried to put it into an Int32, you would get this error. You'll need to put some more information in your code about where this is happening in order to pin it down. Good luck!

Share:
20,645
David Božjak
Author by

David Božjak

Tech Manager at Storytel in Lund, Sweden.

Updated on July 06, 2022

Comments

  • David Božjak
    David Božjak almost 2 years

    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()
    
  • David Božjak
    David Božjak almost 15 years
    Thank you. I will need it since it happens extremly rearly and values are not expected to get anywhere near their data type limitations.