SqlConnection connection pool for SQL server : SQL Server Connection Pool : Database C# Source Code


Custom Search

C# Source Code » Database » SQL Server Connection Pool »

 

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();
    }
  }
}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Database
» SQL Server Connection Pool