SqlConnection connection pool for SQL server : SQL Server Connection Pool « Database ADO.net « C# / C Sharp






SqlConnection connection pool for SQL server

using System;
using System.Data;
using System.Data.SqlClient;

class ConnectionPooling {
  public static void Main() {
    SqlConnection mySqlConnection =
      new SqlConnection("server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;" +
        "max pool size=10;min pool size=5"
      );

    for (int count = 1; count <= 10; count++)
    {
      Console.WriteLine("count = "+ count);

      DateTime start = DateTime.Now;

      mySqlConnection.Open();

      TimeSpan timeTaken = DateTime.Now - start;

      Console.WriteLine("Milliseconds = "+ timeTaken.Milliseconds);

      Console.WriteLine("mySqlConnection.State = "+mySqlConnection.State);

      mySqlConnection.Close();
    }
  }
}

           
       








Related examples in the same category