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?
This question is related to
.net
sql-server
sql-server-2008
ado.net
database-connection
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 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/
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.
Running the following command worked for me:
netsh Winsock reset
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:
Open SQL Server Configuration Manager (depending on what version of SQL Server you're running):
Select SQL Server Services
Locate the troubled service and view Properties
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:
You production server allows remote connections. (possible that someone turned this off, especially if you have a DBA)
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.
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.
Source: Stackoverflow.com