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).
我运行的服务进行一些计算,并且每分钟左右与ms sql服务器通信(24/7,正常运行时间非常重要),如果发生任何有趣的事情(如超时或丢失连接),则写入错误日志。
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.
由于这是在客户端运行,并且该异常仅在项目启动后发生了3次(现在几个月),因此很难捕获和调试。
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.
我正在使用OleDbDataAdapter与服务器进行通信。从服务器收到的数据并没有什么特别之处,我至少知道这一点!数据不应超过字段大小等,因此我无法真正想到发生此错误的原因。再次,这是非常难以验证,因为我得到的是错误消息。
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对象期间实际发生了此错误。代码看起来像这样:
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 ...
EDIT2:我刚想到这个...是否可能抛出此异常,因为系统没有足够的系统资源来完成填充?这是我能想到的唯一可以解释异常发生的原因。它也可以解释为什么它只发生在某些服务器上而且永远不会发生在开发服务器上......
EDIT3: Here is the whole exception in case it gives anyone any more insight:
编辑3:如果它给任何人更多的洞察力,这是完整的例外:
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()
5 个解决方案
#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.
如果您正在对数据上的聚合进行计算,那么它似乎会产生比表结构所期望的更大的结果。
#2
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!
当您的数字太大或太小而无法适应某种数据类型时,通常会发生这种情况。因此,如果你有120398018209571037这样的数字,并试图把它放入Int32,你会得到这个错误。您需要在代码中添加一些有关这种情况的更多信息,以便将其固定下来。祝好运!
#3
I was doing a select and filling a DataAdapter
with the results. This code is inside a loop and before the loop ends, I clear my DataTable: varDataTable.Clear()
.
我正在做一个选择并用结果填充DataAdapter。这段代码在循环内部,在循环结束之前,我清除了我的DataTable:varDataTable.Clear()。
ex:
varStrSQL = "select * from my_table where field_whatever = 2 and id_fk = 4"
varDataAdapter = New SqlDataAdapter(varStrSQL, MyConexion)
varDataAdapter.Fill(varDataTable)
varDataAdapter.Dispose()
But after a 65xxx records, I received the error Arithmetic operation resulted in an overflow
.
但是在65xxx记录之后,我收到错误算术运算导致溢出。
I'm not sure, but I think the datatable was "dimensioned" with the initial results. Obviously, my first records were integers.
我不确定,但我认为数据表是用初始结果“标注”的。显然,我的第一个记录是整数。
To solve this I don't clear the DataTableTasas, I release it as follows:
要解决这个问题,我不清除DataTableTasas,我将其发布如下:
varDataTableTasas = Nothing
varDataTableTasas = New Data.DataTable
Hope this helps.
希望这可以帮助。
#4
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.
当我使用VS.Net 2013和SQL Server作为后端时,我解决了这个问题。只需将项目构建设置设置为“x86”而不是“Any cpu”。然后你去但当然,您需要先检查您的要求。
#5
I had this issue, but only when connecting from a web application running under IIS. The solution in my case was:
我有这个问题,但只有从IIS下运行的Web应用程序连接时才有。我的解决方案是:
- Open IIS
- Browse to the application pool used by my application
- Click "Advanced Settings"
- Change the option "Enable 32-Bit Applications" to "True"
- Click "OK"
浏览到我的应用程序使用的应用程序池
点击“高级设置”
将“启用32位应用程序”选项更改为“True”
I didn't even have to restart the application pool, the change fixed the problem immediately.
我甚至没有重启应用程序池,更改立即修复了问题。
#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.
如果您正在对数据上的聚合进行计算,那么它似乎会产生比表结构所期望的更大的结果。
#2
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!
当您的数字太大或太小而无法适应某种数据类型时,通常会发生这种情况。因此,如果你有120398018209571037这样的数字,并试图把它放入Int32,你会得到这个错误。您需要在代码中添加一些有关这种情况的更多信息,以便将其固定下来。祝好运!
#3
I was doing a select and filling a DataAdapter
with the results. This code is inside a loop and before the loop ends, I clear my DataTable: varDataTable.Clear()
.
我正在做一个选择并用结果填充DataAdapter。这段代码在循环内部,在循环结束之前,我清除了我的DataTable:varDataTable.Clear()。
ex:
varStrSQL = "select * from my_table where field_whatever = 2 and id_fk = 4"
varDataAdapter = New SqlDataAdapter(varStrSQL, MyConexion)
varDataAdapter.Fill(varDataTable)
varDataAdapter.Dispose()
But after a 65xxx records, I received the error Arithmetic operation resulted in an overflow
.
但是在65xxx记录之后,我收到错误算术运算导致溢出。
I'm not sure, but I think the datatable was "dimensioned" with the initial results. Obviously, my first records were integers.
我不确定,但我认为数据表是用初始结果“标注”的。显然,我的第一个记录是整数。
To solve this I don't clear the DataTableTasas, I release it as follows:
要解决这个问题,我不清除DataTableTasas,我将其发布如下:
varDataTableTasas = Nothing
varDataTableTasas = New Data.DataTable
Hope this helps.
希望这可以帮助。
#4
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.
当我使用VS.Net 2013和SQL Server作为后端时,我解决了这个问题。只需将项目构建设置设置为“x86”而不是“Any cpu”。然后你去但当然,您需要先检查您的要求。
#5
I had this issue, but only when connecting from a web application running under IIS. The solution in my case was:
我有这个问题,但只有从IIS下运行的Web应用程序连接时才有。我的解决方案是:
- Open IIS
- Browse to the application pool used by my application
- Click "Advanced Settings"
- Change the option "Enable 32-Bit Applications" to "True"
- Click "OK"
浏览到我的应用程序使用的应用程序池
点击“高级设置”
将“启用32位应用程序”选项更改为“True”
I didn't even have to restart the application pool, the change fixed the problem immediately.
我甚至没有重启应用程序池,更改立即修复了问题。