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?

  • Execute SQL Query from excel
  • Table using too much disk space
  • SQL Server query to group sequential date data
  • How to use Stored Procedure in SqlCE
  • SQL Substring Issue
  • Is it possible to use MS VS Database Project as a complete solution for database versioning?
  • 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?

  • asp.net survey questionnaire engine
  • Mapping to a nested class
  • With SubSonic is there a way to express relationships without foreign keys?
  • Best way to represent a color in a SQL Database?
  • How to use parameter with LIKE in Sql Server Compact Edition
  • What is massively parallel processing (MPP)?
  • 16 Solutions collect form web for “A connection was successfully established with the server, but then an error occurred during the pre-login handshake”


    1) Clean your VS.Net Solution

    2) Rebuild Project.

    3) Reset IIS

    4) Run the project again.

    Basically that solved my problem, but in my case i was not getting this error and suddenly my local environment starts giving me above error, so may be that trick work for me.

    – I saved my work,
    – Closed Visual Studio, then
    – Re-opened my project

    Always works for me.

    Running the following command worked for me:

    netsh Winsock reset

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

    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 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 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!

    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

    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 it was:

    Persist Security Info=True;

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

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

    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

    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.

    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.

    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.

    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.

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.