加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql-server – SQL Server登录前握手

发布时间:2020-12-12 06:38:24 所属栏目:MsSql教程 来源:网络整理
导读:我通过我的ASP .NET应用程序连接到MSSQL数据库,但有时我在打开连接时出现此错误. Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login hand
我通过我的ASP .NET应用程序连接到MSSQL数据库,但有时我在打开连接时出现此错误.

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=3; handshake=14996;

暂时解决它我要重新启动IIS.我正在使用此代码段连接到MSSQL:

using (SqlConnection connection = new SqlConnection(connectionString))
        {
            connection.Open();

            /* my commands here */

            connection.Close();
            connection.Dispose();
            SqlConnection.ClearPool(connection);
        }

我在入站和出站规则中允许端口1433,但没有更改.当我按照那里的指示:

> SQL Server Pre-Login Handshake Acknowledgement Error
> Connection to SQL Server Works Sometimes

但没有改变.

解决方法

根据MSDN Doc.

ClearPool clears the connection pool that is associated with the connection.If additional connections associated with connection are in use at the time of the call,they are marked appropriately and are discarded (instead of being returned to the pool) when Close is called on them.

你应该在connection.close之前使用ClearPool方法

参考:https://msdn.microsoft.com/zh-tw/library/system.data.sqlclient.sqlconnection.clearpool(v=vs.110).aspx

如果使用Using语法来管理Object,则不应使用connection.close方法

因为它会在它们结束时调用.只需打开您的连接并执行您的命令

using (SqlConnection connection = new SqlConnection(connectionString))
    {
        connection.Open();
        SqlConnection.ClearPool(connection);
        /* my commands here */
        SqlCommand cmd = new SqlCommand("your command",conn);
        cmd.ExecuteReader()


    }

参考例:https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

最后确保SQL Server网络配置是正确的

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读