Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arithmetic overflow exception when opening SQL connection

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()
like image 997
Red Developer Avatar asked Sep 16 '15 12:09

Red Developer


People also ask

How do you fix arithmetic overflow in SQL?

You need to increase the width of the variable to store this number e.g. making @sample NUMERIC (6,2) will solve this error.

What is arithmetic overflow in SQL?

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.

Is arithmetic overflow an exception?

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.

What does arithmetic overflow error convert to data type int mean?

"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.

What is arithmetic overflow error in SQL Server?

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]

What does system overflowexception mean?

System.OverflowException: Arithmetic operation resulted in an overflow. 2017-01-23 21:16:17.436 +00:00 [Error] Arithmetic operation resulted in an overflow.

What is the arithmetic overflow error for data type smallint?

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?

What is arithmetic overflow in C?

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.


4 Answers

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.

like image 89
Kim Gybels Avatar answered Oct 23 '22 05:10

Kim Gybels


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.

  1. I stopped the service LavasoftTcpService (from services.msc)
  2. I uninstalled WebCompanion from Program and Features.
  3. Two above mentioned dlls (LavasoftTcpService.dll and LavasoftTcpService64.dll in C:\Windows\System32 and C:\Windows\SysWOW64) were still there. I changed their name, and a problem dissapeared.

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.

like image 36
Ursula Avatar answered Oct 23 '22 05:10

Ursula


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.

like image 42
seguso Avatar answered Oct 23 '22 05:10

seguso


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.

like image 24
David McA Avatar answered Oct 23 '22 06:10

David McA