15

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()
11
  • I don't suppose you're able to consistently reproduce this? Is it just one application or several?
    – Dan Field
    Sep 16, 2015 at 12:55
  • is there a checked integer addition anywhere in your code? can you post the full exception please? Sep 16, 2015 at 13:06
  • @Dan Field - It's reproducable from time to time and even quite often - not sure under what conditions, since this exception had occured on few of my customer's machines. Thus I can't debug the code myself :/ And exactly the same problem I have in three different applications (the stack trace is same). Sep 16, 2015 at 13:34
  • @user1666620 There is nothing like this in my code, since I do not do any computations related to the connection - the exception occurs in core .net code. The trace shown above is the full stack trace from the exception (previous operations, before the Open method on SqlConnection is called, are not relevant at all). And by the way - this is a call from single thread. It's not the case multiple threads try open the connection. Sep 16, 2015 at 13:42
  • 1
    tbh might be best to log a ticket with microsoft support. Sep 16, 2015 at 13:56

6 Answers 6

20

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.

3
  • I applied the steps and I've been checking for couple of days and it seems it helped. The problem didn't occur from that moment. Maybe it should be complained to Lavasoft or something...
    – Bronek
    Nov 17, 2016 at 13:20
  • Thank you for this, I really wasn't able to understand what was happening to my colleague sql server, any call to Open connection from a C# program gave this absurd overflow error on SQL Client. Someone should send a message to Lavasoft.
    – Sabrina_cs
    Mar 29, 2017 at 9:51
  • I'm not able to see the root of the problem, but it's simply working. Thanks a lot!
    – Oswald
    Jul 27, 2017 at 6:28
11

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.

1
3

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.

2

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.

2

i had the same problem while creating user through entityframework and i found the solution and fix the problem by doing following steps

  1. Stop LavasoftTcpService64 service from services and
  2. Uninstall the web-companion from program and features and it started working in case if the problem still exist restart your machine hope it will help.
1

I Just encountered this error myself and option #2 from here helped me.

  1. Please, start Command Prompt as an administrator by right-clicking it and select Run as administrator.

  2. Enter this command to reset the network adapter (end with the Enter key):
    netsh winsock reset

  3. Restart the computer.

  4. Please, delete these two files:
    C:\WINDOWS\system32\LavasoftTcpService64.dll C:\WINDOWS\SysWOW64\LavasoftTcpService.dll (only for 64-bit Windows)

I renamed the files instead of deleting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.