Enable connection pooling string constr = "Data sourse=zxtiger; Initial catalog=itcastcn;integrated security=true "; Stopwatch watch = new Stopwatch (); Watch. Start (); for (int i = 0; i < i++) { using (SqlConnection con = new SqlConnection (constr)) { con. Open (); Con. Close (); } } Watch. Stop (); Console.WriteLine (watch. Elapsed); Console.readkey ();
Once connection pooling is enabled, only one connection operation is performed
Disable connection pooling string constr = "Data sourse=zxtiger; Initial catalog=itcastcn;integrated security=true; Pooling=false "; Stopwatch watch = new Stopwatch (); Watch. Start (); for (int i = 0; i < i++) { using (SqlConnection con = new SqlConnection (constr)) { con. Open (); Con. Close (); } } Watch. Stop (); Console.WriteLine (watch. Elapsed); Console.readkey ();
Connection pooling is turned on by default when the connection pool is disabled
00:00:00.1383385
00:00:03.9974913
Before and after the difference 29 is
The benefit of connection pooling is that you keep the connection object, preventing you from instantiating a connection object the next time.
Because each normal connection database performs at least 3 operations (1. Log on to database server 2. Perform operation 3. Log off the user), so it is time-consuming to request a connection to the database server via Connection "ADO-enabled connection pooling by default"
ADO Connection Pool Effect