SQL Server Login Start Statement

I connect to the MSSQL database through my ASP.NET application, but sometimes I get this error when opening a connection.

Connection timed out. The waiting period has expired while trying to use an authorization confirmation confirmation before entering the system. This may be due to the fact that the handshake before entering the system failed or the server was unable to respond on time. The duration spent trying to connect to this server was - [Pre-Login] initialization = 3; acknowledgment = 14996;

To solve this problem, I have to restart IIS. I use this piece of code to connect to MSSQL:

using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); /* my commands here */ connection.Close(); connection.Dispose(); SqlConnection.ClearPool(connection); } 

I allowed port 1433 in the inbound and outbound rules, but no changes. When I follow the instructions:

but nothing has changed.

+6
source share
1 answer

According to MSDN Doc.

ClearPool cleans up the connection pool that is associated with the connection. If additional connections associated with the connection are used during a conversation, they are appropriately marked and discarded (instead of returning to the pool) when Close called them.

you must use the ClearPool method before connecting .close

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

And if you use "Use syntax to control the object", you should not use the connection.close method

because it is called when they end. just open your connection and run the command

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

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

last ensure proper SQL Server network configuration

enter image description here

enter image description here

+2
source

Source: https://habr.com/ru/post/976671/


All Articles