I got very weird ArithmeticOverflowException
when opening an SQL connection to the underlying SQL database (stack trace included below). It doesn't make a difference which version of the server is used (I've verified MS SQL 2005/2008/2012/2014), error is still the same. All the newest updates and patches from Windows Update installed. OS is Windows 8.1 / 10 (same occurs on both systems). Server is installed locally and the connection is made via user and password. Connection timeout verified in range from 15 to 1000 sec.
The most surprising thing is the application works just fine, and communicates with the server properly, executing many various queries, but suddenly this exception occurs. I noticed this exception started showing up after some windows update (no idea which one).
I've looked into the .NET code, but have no idea what can cause the arithmetic overflow exception there...
-- STACK TRACE --
in SNIOpenSyncExWrapper(SNI_CLIENT_CONSUMER_INFO* , SNI_ConnWrapper** )
in SNINativeMethodWrapper.SNIOpenSyncEx(ConsumerInfo consumerInfo, String constring, IntPtr& pConn, Byte[] spnBuffer, Byte[] instanceName, Boolean fOverrideCache, Boolean fSync, Int32 timeout, Boolean fParallel)
in System.Data.SqlClient.SNIHandle..ctor(ConsumerInfo myInfo, String serverName, Byte[] spnBuffer, Boolean ignoreSniOpenTimeout, Int32 timeout, Byte[]& instanceName, Boolean flushCache, Boolean fSync, Boolean fParallel)
in System.Data.SqlClient.TdsParserStateObject.CreatePhysicalSNIHandle(String serverName, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Byte[]& instanceName, Byte[] spnBuffer, Boolean flushCache, Boolean async, Boolean fParallel)
in System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover)
in System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
in System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
in System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
in System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData)
in System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
in System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
in System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
in System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
in System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
in System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
in System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
in System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
in System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
in System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
in System.Data.SqlClient.SqlConnection.Open()
You need to increase the width of the variable to store this number e.g. making @sample NUMERIC (6,2) will solve this error.
The error "Arithmetic overflow error converting IDENTITY to data type int" comes when IDENTITY value is inserted into a column of data type int, but the value is out-of-range.
With the default setting, C# compiler will not throw an exception if arithmetic overflow happens. The above program will not throw an exception and work fine because C# compiler is configured in that way.
"Arithmetic overflow error converting IDENTITY to data type int" error means the value of IDENTITY is overflowing range of data type of that particular column.
Before considering the query, let’s spend few seconds to understand the error we are facing. Arithmetic overflow error converting an expression to data type int. Which means, there is a value being passed to a column which is greater than the Integer Datatype [2,147,483,647]
System.OverflowException: Arithmetic operation resulted in an overflow. 2017-01-23 21:16:17.436 +00:00 [Error] Arithmetic operation resulted in an overflow.
Arithmetic overflow error for data type smallint, value = xxxxx 0 Casting fraction number to decimal throws Arithmetic overflow error Hot Network Questions Should a competitive cyclist be concerned with CO2 tolerance?
An arithmetic overflow is the result of a calculation that exceeds the memory space designated to hold it. For example, a divide-by-zero yields a much larger result. See arithmetic underflow. How do you solve arithmetic operation resulted in an overflow? Solution: Use an Int64 for your volume.
We had the same problem and it was caused by LavasoftTcpService64.dll
. Getting rid of this, which is not that easy, fixed the problem. Check the following folders for its presence: C:\Windows
, C:\Windows\System32
and C:\Windows\SysWOW64
.
Credit goes to Nguyen Quy Hy for finding the root cause.
I had the same problem. Lavasoft was also a reason. I checked in Program and Features if there is any Lavasoft program, and I was surprised to find application called WebCompanion of Lavasoft. I also found a running service LavasoftTcpService.
Before those steps I tried to only change dlls names and there was a problem to resolve localhost: instead of 127.0.0.1 system was looking for 0.0.0.0. Ping was giving me an error message "Ping request could not find host localhost. Please check the name and try again"
3 steps resolved the problem.
I confirm the culprit is Lavasoft Ad-Aware or WebCompanion. The System.OverflowException is thrown when calling SqlConnection.Open(). Only with LocalDB.
Interestingly, the crash occurs always if your app is a single instance application, otherwise it occurs randomly.
The solution is what Ursula said.
I had the same problem which prevented installation of Azure Storage Emulator i.e. AzureStorageEmulator.exe start produced a similar stack trace and exception. I could init the emulator but not start it. Removal of the Lavasoft dll and resetting the winsock stack did the trick. So worked for me and likewise credit to Nguyen Quy Hy and this post.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With