Sql 错误“算术运算导致溢出。”
我正在运行一个服务,它会进行一些计算,并每分钟左右与 ms sql 服务器进行通信(24/7,正常运行时间非常重要),并在发生任何有趣的情况(例如超时或丢失连接)时写入错误日志。
这很有效,但是偶尔我会收到此错误:
算术运算导致溢出。
由于这是在客户端运行的,并且自项目启动以来(现在已经几个月了),异常只发生了 3 次,这将非常难以捕获和调试。
我正在使用 OleDbDataAdapter 与服务器进行通信。 从服务器接收到的数据在任何方面都没有什么特殊之处,至少我知道! 数据永远不应该超过字段大小等,所以我真的想不出发生此错误的原因。 同样,这非常难以验证,因为我收到的只是错误消息。
我的问题是:为什么通常会出现此错误? 我在网上找不到任何有关它的真实信息,所以如果有人可以向我提供一些信息,我将不胜感激。
谢谢你!
编辑:仔细阅读错误报告后发现,此错误实际上是在填充 DataTable 对象期间发生的。 代码看起来像这样:
DataTable.Clear();
try
{
oledbdataAdapter.Fill(DataTable, sqlString);
}
catch (Exception e)
{
//error has occured, report
}
有人能理解这一点吗?
EDIT2:我刚刚想到了这一点...是否有可能因为系统没有足够的系统资源来完成填充而抛出此异常? 这是我能想到的唯一可以解释异常发生的原因。 它还可以解释为什么它只发生在某些服务器上,而不会发生在开发服务器上...
编辑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()
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您正在对数据进行聚合计算,那么它似乎会产生比表结构预期的更大的结果。
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.
当我使用 VS.Net 2013 以 SQL Server 作为后端时,我解决了这个问题。 只需将项目构建设置设置为“x86”而不是“任何 cpu”。 就这样吧。 但当然,您需要先检查您的要求。
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.
我遇到了这个问题,但仅限于从 IIS 下运行的 Web 应用程序进行连接时。 我的解决方案是:
我什至不必重新启动应用程序池,更改立即解决了问题。
I had this issue, but only when connecting from a web application running under IIS. The solution in my case was:
I didn't even have to restart the application pool, the change fixed the problem immediately.
当您的数字太大或太小而不适合某种数据类型时,通常会发生这种情况。 因此,如果您有数字 120398018209571037 并尝试将其放入 Int32 中,您将收到此错误。 您需要在代码中添加一些有关发生这种情况的更多信息,以便确定它。 祝你好运!
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!
我正在执行选择并用结果填充
DataAdapter
。 此代码位于循环内,在循环结束之前,我清除了 DataTable:varDataTable.Clear()
。例如:
但是在 65xxx 记录之后,我收到错误
算术运算导致溢出
。我不确定,但我认为数据表是根据初始结果“确定尺寸”的。 显然,我的第一个记录是整数。
为了解决这个问题,我不清除 DataTableTasas,我将其释放如下:
希望这有帮助。
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()
.ex:
But after a 65xxx records, I received the error
Arithmetic operation resulted in an overflow
.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:
Hope this helps.