Probably, you are handling SqlConnection objects badly: if you do not close and dispose them when you are finished with them they will remain open until the Garbage Collector gets fired up because your app runs out of memory, or your app closes - whichever happens first. If you exhaust the connection pool before the GC does anything, or your app closes, you will get this error.
The simplest way around this is to always enclose your SqlConnection objects in a
using
block:
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("SELECT Id, description FROM myTable", con))
{
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
int id = (int) reader["Id"];
string desc = (string) reader["description"];
Console.WriteLine("ID: {0}\n {1}", id, desc);
}
}
}
}
When you do that, the connection is Closed and Disposed automatically when the variable goes out of scope, so your connections do not get left around for the GC. Note that SqlCommand objects and such like are also scarce resources and should be treated the same way.