Ahm*_*egm 10 sql-server handshake sslhandshakeexception
我通过我的ASP .NET应用程序连接到MSSQL数据库,但有时我在打开连接时遇到此错误.
连接超时已过期.尝试使用登录前握手确认时超时时间已过.这可能是因为登录前握手失败或服务器无法及时响应.尝试连接到此服务器所花费的时间是 - [Pre-Login] initialization = 3; 握手= 14996;
暂时解决它我要重新启动IIS.我正在使用此代码段连接到MSSQL:
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
/* my commands here */
connection.Close();
connection.Dispose();
SqlConnection.ClearPool(connection);
}
Run Code Online (Sandbox Code Playgroud)
我在入站和出站规则中允许端口1433,但没有更改.当我按照那里的指示:
但没有改变.
根据 MSDN 文档。
ClearPool 清除与连接关联的连接池。如果在调用时正在使用与连接关联的其他连接,则会对它们进行适当标记,并在对它们调用 Close 时将其丢弃(而不是返回到池中) 。
你应该在connection.close之前使用ClearPool方法
参考: https: //msdn.microsoft.com/zh-tw/library/system.data.sqlclient.sqlconnection.clearpool (v=vs.110).aspx
如果您使用使用语法来管理对象,则不应使用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()
}
Run Code Online (Sandbox Code Playgroud)
最后确保 SQL Server 网络配置正确
| 归档时间: |
|
| 查看次数: |
9706 次 |
| 最近记录: |