简体   繁体   English

SQL错误“算术运算导致溢出。”

[英]Sql error “Arithmetic operation resulted in an overflow.”

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). 我正在运行一项服务,该服务执行一些计算并每分钟左右(24/7,正常运行时间非常重要)与ms sql服务器通信,并且如果发生任何有趣的事情(例如超时或连接断开),则将其写入错误日志。

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. 我正在使用OleDbDataAdapter与服务器通信。 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. 编辑 :仔细阅读错误报告后,我发现该错误实际上是在DataTable对象的填充过程中发生的。 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? EDIT2 :我刚刚想到了这一点...是否可能因为系统没有足够的系统资源来完成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 ... 它还将解释为什么它仅在某些服务器上发生而从不在dev服务器上发生...

EDIT3 : Here is the whole exception in case it gives anyone any more insight: EDIT3 :这是整个异常,以防万一它给任何人更多的见解:

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

如果您要对数据的聚合进行计算,那么看起来会导致更大的结果,这是表结构所期望的。

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. 因此,如果您有数字120398018209571037,并尝试将其放入Int32中,则会收到此错误。 You'll need to put some more information in your code about where this is happening in order to pin it down. 您需要在代码中放入一些更多有关此情况发生的信息,以便进行锁定。 Good luck! 祝好运!

I was doing a select and filling a DataAdapter with the results. 我正在做一个选择,并用结果填充DataAdapter This code is inside a loop and before the loop ends, I clear my DataTable: varDataTable.Clear() . 这段代码在循环内,在循环结束之前,我清除了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之后,我收到了错误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: 为了解决这个问题,我不清除DataTableTasas,而是按以下方式释放它:

varDataTableTasas = Nothing
varDataTableTasas = New Data.DataTable

Hope this helps. 希望这可以帮助。

I solved the problem when I was using VS.Net 2013 with SQL Server as backend. 当我将VS.Net 2013与SQL Server用作后端时,我解决了该问题。 Just set the project build settings to "x86" instead of "Any cpu". 只需将项目构建设置设置为“ x86”,而不是“ Any cpu”。 and there you go. 然后你去。 But of-course you need to check your requirements first. 当然,您首先需要检查您的需求。

I had this issue, but only when connecting from a web application running under IIS. 我遇到了这个问题,但是仅当从在IIS下运行的Web应用程序进行连接时才出现。 The solution in my case was: 我的解决方案是:

  1. Open IIS 打开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" 将选项“启用32位应用程序”更改为“真”
  5. Click "OK" 点击“确定”

I didn't even have to restart the application pool, the change fixed the problem immediately. 我什至不必重启应用程序池,更改立即解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 算术运算导致溢出。 在oAuthTwitterWrapper中 - Arithmetic operation resulted in an overflow. in oAuthTwitterWrapper 算术运算导致溢出。 (加整数) - Arithmetic operation resulted in an overflow. (Adding integers) 算术运算导致溢出。 在AS400中删除数据时 - Arithmetic operation resulted in an overflow. When Delete Data in AS400 protobuf-net反序列化:“算术运算导致溢出。” - protobuf-net deserializing: “Arithmetic operation resulted in an overflow.” System.OverflowException:'算术运算导致溢出。' - System.OverflowException: 'Arithmetic operation resulted in an overflow.' WinForm控件ListView“算术运算导致溢出。” - WinForm Control ListView “Arithmetic operation resulted in an overflow.” FileStream获取错误算术运算导致溢出 - FileStream get error Arithmetic operation resulted in an overflow 算术运算导致溢出错误C# - Arithmetic operation resulted in an overflow error c# 为什么找不到此HashSet的Sum()。 说:“算术运算导致溢出。” - Why can't I find Sum() of this HashSet. says “Arithmetic operation resulted in an overflow.” CSharp:无法读取大型 .npy 文件。 例外是“NumSharp.dll 算术运算导致溢出。” - CSharp: Failed to read LARGE .npy file. Exception is "NumSharp.dll Arithmetic operation resulted in an overflow."
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM