[.net] A connection was successfully established with the server, but then an error occurred during the pre-login handshake

I am getting following error when i am trying to connect Production DB from Local Environment.

I was able to connect Production DB before, but suddenly i am getting following error, any idea?

A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - The handle is invalid.)

I was trying to run asp.net website in local PC, which has connection string of Production DB, following is stack trace for error I am getting in local environment.

>    at MyWebsiteDAL.clsForumQuestion.SelectAll(Int32 CurrentPageIndex, Int32 PageSize) in D:\EDrive\My WebSites\MyWebsite\MyWebsite\MyWebsiteDAL\clsForumQuestion.cs:line 821
       at CodeConnect.Default.Page_Load(Object sender, EventArgs e) in D:\EDrive\My WebSites\MyWebsite\MyWebsite\MyWebsite\Default.aspx.cs:line 100
       at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
       at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Any idea what might have gone wrong here?

The answer is


I had this same problem and was having no luck with the suggested fixes. I then came across this article and saw the comment from Mirrh regarding a program called Sendori blocking the LSP. No idea how it got on my computer but there it was and removing it fixed the issue.

If the article doesn't work just check your Programs and uninstall Sendori if you see it.


In my case, i was getting the error when i wanted to access a remote database. However, i solved it by starting SQL Server Browser service.

enter image description here


In my case this error occurred with dot net core and Microsoft.Data.SqlClient. The solution was to add ;TrustServerCertificate=true to the end of the connection string.


Tried most of the above and nothing worked. Then turned off the VPN software (NordVPN) and everything was fine.


I tried many solutions in the past month, none has worked. The problem is the Production DB is within a VPN and somehow the ISP provider thinks the HTTP connection is not secure. However, I was able to connect to the same Production DB from SSMS (uses TCP).

My solution: use the mobile phone as a hotspot and use mobile data instead of my office/home Wi-Fi.


If you are connecting to an old SQL Server:

Switch from System.Data.SqlClient.SqlConnection to System.Data.OleDb.OleDbConnection

Use an OleDb connection string:

<connectionStrings>
<add name="Northwind" connectionString="Provider=SQLOLEDB.1; Data Source=MyServer; Initial Catalog=Northwind;  Persist Security Info=True; User ID=abc; Password=xyz;" providerName="System.Data.OleDb" />
</connectionStrings>

Had the same problem from many days. I had to explicitly add TLS1.2 support in my core project to address this error and it worked fine. ( ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;)

See below link for more details (thanks to author Usman Khurshid) https://www.itechtics.com/connection-successfully-established-error-occured-pre-login-handshake/


  • Save your work,
  • Close Visual Studio, then
  • Re-open your project

This worked for me.


For me the solution is to kill zombie IIS express worker processes.

e.g. locate in Task Manager and end task.

enter image description here


Running the following command worked for me:

netsh Winsock reset

Seen at https://serverfault.com/a/487139/250527


I had the same problem, I was storing session data in the database, the connection string had Encrypt=True in it, which I assume told the sql client to connect to the server in secure (SSL) mode, removing this helped!


Had the same issue, the reason for it was BCrypt.Net library, compiled using .NET 2.0 framework, while the whole project, which used it, was compiling with .NET 4.0. If symptoms are the same, try download BCrypt source code and rebuild it in release configuration within .NET 4.0. After I'd done it "pre-login handshake" worked fine. Hope it helps anyone.


For me I had this happen on a HyperV virtual machine that was accessing my database on my local (host) machine. Basically it all works normally, but after a reboot there is some weird condition that this error starts coming up from the virtual machine applications. There is something in the network layer that is getting horribly confused. However, I have found if I ping the virtual server from the host server, it seems to fix the problem (not sure why exactly). But this might help someone.


I was getting the exact same problem with no chnges to the code base or servers. It turned out to be that the DB server was running at 100% CPU and SQL Server was being starved of any CPU time, which caused the timeout.


In my case, it was a TLS protocol mismatch between a Raspberry Pi hosting a .Net Core 3.1 app requesting to a Windows Server 2012 with MSSQL. I tried many changes of TLS protocol version on the Windows Server side without any effect. I finally found this post https://github.com/dotnet/SqlClient/issues/126, indicating modify the client side, ie to update the /etc/ssl/openssl.cnf on the RPi side, and that worked great for me.


I experienced this error when running some very memory-expensive processes. When the system started to run short of memory, I begun to notice this kind of error. I had to change the algorithm in order to make a better use of RAM.

To be noted that while some threads threw this exception, some other threw:

System.Data.SqlClient.SqlException (0x80131904): Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=43606; handshake=560; ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out

Both problems disappeared after the system was changed so that it could run using less RAM.


I experienced this error and did all the suggestions from you guys here but none had any effect for my error.

I caught the culprit: if you are using *.ini file for your system, you might want to check what server name was input there and make sure it is the same as the one in your web.config connection string.


Same problem here and no answers listed here worked, nor any solutions I could find online. The issue started shortly after Windows 10 anniversary update got applied on my dev PC and only affected my old SQL Server 2005 instance. I was not able to connect to the instance via my Web Applications or even using Sql Management Studio.

For what it's worth, this is what resolved it for me:

  1. Open SQL Server Configuration Manager (depending on what version of SQL Server you're running):

    • C:\Windows\SysWOW64\SQLServerManager.msc
    • C:\Windows\SysWOW64\SQLServerManager10.msc OR
    • C:\Windows\SysWOW64\SQLServerManager12.msc OR
    • etc
  2. Select SQL Server Services

  3. Locate the troubled service and view Properties

    • eg SQL Server (SQL2005) in my case
  4. In the Log On tab, change the "Built-in account" to "Network Service"

Which is almost what this random solution said: http://www.kutayzorlu.com/operating-systems/linux-unix-redhat-debian-ubuntu-opensuse-centos/general-server-administrating/error-fixed-a-connection-was-successfully-established-with-the-server-but-then-an-error-occurred-during-the-pre-login-handshake-12405.html

I chose Network Service for no reason at all. Mine was already configured to use Local System. This security doesn't matter to me as it was only problematic on my Local development machine, only accessed locally. I can't advise why this works, but it did.


As described in the answer of Ricardo ,

netsh Winsock reset

has worked for me ,

P.S. if you have Internet download manager or such programs which changes you IP Setting is installed then after running this command when you reboot your computer IDM will ask to change setting , Set NO in this case and then run your application it will work correctly.

Hope it


In my case it was:

Persist Security Info=True;

in my connection string that needed to be removed. Once I did that I no longer had issues.


You might want to check a few things:

  1. You production server allows remote connections. (possible that someone turned this off, especially if you have a DBA)

  2. Check your connection string. Sometimes if you are using an ip address or server name this will cause this error. Try both.


I restarted SQL Server (Sharepoint) service and it solved the issue.


I had a similar issue where I couldn't connect to a database and tried the recommendations here.

At the end of the day this is what worked for me:

Used the SQL Server Configuration Manager tool to enable the TCP/IP and/or the Named Pipes protocols on the SQL Server client computer.

  1. Click Start, point to All Programs, and click SQL Server Configuration Manager.
  2. Click to expand SQL Server Network Configuration and then click Client Protocols.
  3. Right-click the TCP/IP protocol and then click Enable.
  4. Right-click the Named Pipes protocol and then click Enable.
  5. Restart the SQL server service if prompted to do so.

I am still not sure why or when this was disabled.


In my case, Re-enabling TLS 1.0 in the DB server resolved this issue.


Examples related to .net

You must add a reference to assembly 'netstandard, Version=2.0.0.0 How to use Bootstrap 4 in ASP.NET Core No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization .net Core 2.0 - Package was restored using .NetFramework 4.6.1 instead of target framework .netCore 2.0. The package may not be fully compatible Update .NET web service to use TLS 1.2 EF Core add-migration Build Failed What is the difference between .NET Core and .NET Standard Class Library project types? Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies Nuget connection attempt failed "Unable to load the service index for source" Token based authentication in Web API without any user interface

Examples related to sql-server

Passing multiple values for same variable in stored procedure SQL permissions for roles Count the Number of Tables in a SQL Server Database Visual Studio 2017 does not have Business Intelligence Integration Services/Projects ALTER TABLE DROP COLUMN failed because one or more objects access this column Create Local SQL Server database How to create temp table using Create statement in SQL Server? SQL Query Where Date = Today Minus 7 Days How do I pass a list as a parameter in a stored procedure? SQL Server date format yyyymmdd

Examples related to sql-server-2008

Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object How to Use Multiple Columns in Partition By And Ensure No Duplicate Row is Returned SQL Server : How to test if a string has only digit characters Conversion of a varchar data type to a datetime data type resulted in an out-of-range value in SQL query Get last 30 day records from today date in SQL Server How to subtract 30 days from the current date using SQL Server Calculate time difference in minutes in SQL Server SQL Connection Error: System.Data.SqlClient.SqlException (0x80131904) SQL Server Service not available in service list after installation of SQL Server Management Studio How to delete large data of table in SQL without log?

Examples related to ado.net

Error: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient' How to fill a datatable with List<T> Populate data table from data reader Increasing the Command Timeout for SQL command how to resolve DTS_E_OLEDBERROR. in ssis Convert DataSet to List How to connect access database in c# MySQL Data Source not appearing in Visual Studio How do I get values from a SQL database into textboxes using C#? Connection to SQL Server Works Sometimes

Examples related to database-connection

Server Discovery And Monitoring engine is deprecated phpMyAdmin on MySQL 8.0 How does spring.jpa.hibernate.ddl-auto property exactly work in Spring? MySQL Error: : 'Access denied for user 'root'@'localhost' Warning about SSL connection when connecting to MySQL database Fatal error: Call to a member function query() on null How to list active connections on PostgreSQL? How connect Postgres to localhost server using pgAdmin on Ubuntu? Oracle SQL Developer: Failure - Test failed: The Network Adapter could not establish the connection? How to increase MySQL connections(max_connections)?