1. Connection to the database SqlConnection con = new SqlConnection (constr); When you are finished, you should at least close or dispose of it. Failure to do so will result in an increase in the sleeping process in the database such as (SQl2005) and cannot be destroyed by itself, resulting in a "" Connection timeout that has reached the maximum number of connections.
The workaround: See Microsoft's official note "If the SqlConnection is out of range, it will not be closed." Therefore, unless you place the code inside a using statement, you must call Close or Dispose to explicitly close the connection. They are functionally equivalent. If you set the connection pool value Pooling to true or Yes, the physical connection is also released. ”
Https://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqlconnection.close (v=vs.80). aspx
Sqlconnection.clearpool (Con) can be added before 2.Close to clear each connection to prevent an already-connected database connection from entering sleeping and causing the user Connections of the number of connecting users to increase.
C # should close the connection after accessing the database