Skip to content

Instantly share code, notes, and snippets.

@naraga
Created September 18, 2012 22:40
Show Gist options
  • Save naraga/3746449 to your computer and use it in GitHub Desktop.
Save naraga/3746449 to your computer and use it in GitHub Desktop.
What happens when sql connections runs out? You are gonna wait
class Program
{
// connection pool "overflow" demo
private const int ConnSize = 150;
static void Main(string[] args)
{
var connections = new SqlConnection[ConnSize];
for (int i = 0; i < ConnSize; i++)
{
connections[i] = new SqlConnection("Data source=bb5\\bb5;Initial Catalog=chatode;Integrated Security=SSPI; Async=True");
connections[i].Open();
var cmd = new SqlCommand("select * from TheInteger", connections[i]);
IAsyncResult r = cmd.BeginExecuteReader();
Console.WriteLine("conn {0}", i);
}
Console.ReadLine();
for (int i = 0; i < 100; i++)
{
connections[i].Close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment