I have an client application that connects to the DB via the using clause.
using (SqlConnection sqlConn = new SqlConnection(ConnectionString))
{
sqlConn.Open();
//SQLcommand codes
}
I know this will ensure the sqlConnn.Close() and sqlConn.Dispose() to be called. However, for each client after running this code I still see some of the SPID on SQLServer in sleeping mode such as:
60 0 sleeping sa AVENGER 0 Xmark AWAITING COMMAND 0
61 0 sleeping sa AVENGER 0 Xmark AWAITING COMMAND 0
62 0 sleeping sa AVENGER 0 Xmark AWAITING COMMAND 0
I know this is because I use connection pooling in my connection, that is why they are in sleep mode and to reuse again in further command. I see these processes get flushed out over time (after like 10 minutes or so) if I don’t do anything with them.
My question is: Is there a setting either from C# or in SQLServer2008 that will reduce this time to like 2 minutes or so?
The problem I face is my max pooling connection limit reaches quickly if I have many clients connect to the Database around a short period of time. I realize I can fix it by increase my connection pooling, however I think that is like upgrade from a smaller to a bigger bowl to contain water from a leaked roof.
I searched on MSDN and came across the ClearPool() that will let me implicitly remove the SPID from the pool but I think that defeats the purpose of connection pooling and it is not really clean.
any help is greatly appreciated.
You are looking for the ‘Idle Time-out’ setting. It is configured for the application pool in IIS. Refer to this link