.net 已成功与服务器建立连接,但随后在登录前握手时发生错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3270199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 14:31:38  来源:igfitidea点击:

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

.netsql-serversql-server-2008ado.netdatabase-connection

提问by Jordon Willis

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

已成功与服务器建立连接,但在登录前握手期间发生错误。(提供者:TCP 提供者,错误:0 - 句柄无效。)

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.

我试图在本地 PC 上运行 asp.net 网站,它具有生产数据库的连接字符串,以下是我在本地环境中遇到的错误的堆栈跟踪。

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)

在 MyWebsiteDAL.clsForumQuestion.SelectAll(Int32 CurrentPageIndex, Int32 PageSize) 在 D:\EDrive\My WebSites\MyWebsite\MyWebsite\MyWebsiteDAL\clsForumQuestion.cs:line 821 在 CodeConnect.Default.Page_Load(Object sender, EventArgs e) in D: \EDrive\My WebSites\MyWebsite\MyWebsite\MyWebsite\Default.aspx.cs:在 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) 在 System.Web.Util 的第 100 行。 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,布尔值 includeStagesAfterAsyncPoint)

Any idea what might have gone wrong here?

知道这里可能出了什么问题吗?

回答by Jordon Willis

Solution

解决方案

1) Clean your VS.Net Solution

1) 清理你的 VS.Net 解决方案

2) Rebuild Project.

2) 重建项目。

3) Reset IIS

3) 重置 IIS

4) Run the project again.

4) 再次运行项目。

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.

基本上这解决了我的问题,但在我的情况下,我没有收到这个错误,突然我的本地环境开始给我上面的错误,所以这个技巧可能对我有用。

回答by Dumisani

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

- 保存您的工作,
- 关闭 Visual Studio,然后
- 重新打开您的项目

Always works for me.

总是对我来说有效。

回答by Ricardo Stuven

Running the following command worked for me:

运行以下命令对我有用:

netsh Winsock reset

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

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

回答by Starnuto di topo

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.

我在运行一些非常消耗内存的进程时遇到了这个错误。当系统开始运行内存不足时,我开始注意到这种错误。为了更好地利用 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

System.Data.SqlClient.SqlException (0x80131904):连接超时已过期。尝试使用登录前握手确认时超时时间已过。这可能是因为登录前握手失败或服务器无法及时响应。尝试连接到此服务器所花费的时间为 - [Pre-Login] 初始化=43606;握手=560;---> System.ComponentModel.Win32Exception (0x80004005): 等待操作超时

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

更改系统后,这两个问题都消失了,以便它可以使用更少的 RAM 运行。

回答by Terry Kernan

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

我遇到了同样的问题,我将会话数据存储在数据库中,连接字符串中有Encrypt=True,我假设它告诉 sql 客户端以安全(SSL)模式连接到服务器,删除它有帮助!

回答by Richard Fantozzi

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.

  1. 您的生产服务器允许远程连接。(可能有人把它关掉了,特别是如果你有 DBA)

  2. 检查您的连接字符串。有时,如果您使用 IP 地址或服务器名称,则会导致此错误。两个都试试。

回答by delliottg

In my case it was:

就我而言,它是:

Persist Security Info=True;

Persist Security Info=True;

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

在我需要删除的连接字符串中。一旦我这样做了,我就不再有问题了。

回答by daffyjeje

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.

使用 SQL Server 配置管理器工具在 SQL Server 客户端计算机上启用 TCP/IP 和/或命名管道协议。

  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.
  1. 单击开始,指向所有程序,然后单击 SQL Server 配置管理器。
  2. 单击以展开 SQL Server 网络配置,然后单击客户端协议。
  3. 右键单击 TCP/IP 协议,然后单击启用。
  4. 右键单击命名管道协议,然后单击启用。
  5. 如果出现提示,请重新启动 SQL 服务器服务。

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

我仍然不确定为什么或何时禁用此功能。

回答by Vishal Sharma

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.

PS,如果您安装了 Internet 下载管理器或更改 IP 设置的此类程序,则在运行此命令后,当您重新启动计算机时,IDM 将要求更改设置,在这种情况下设置为 NO,然后运行您的应用程序,它将正常工作。

Hope it

希望它

回答by Daniel de Zwaan

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

对我来说,解决方案是杀死僵尸 IIS Express 工作进程。

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

例如在任务管理器中定位并结束任务。

enter image description here

在此处输入图片说明