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:
|