Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
private void button1_Click(object sender, EventArgs e)
{
try
{
//Creating Connection
SqlConnection con = new SqlConnection();
//Connection Sring
con.ConnectionString = string.Format("Data Source={0};Initial Catalog={1};Persist Security Info=True;User ID={2};Password={3}", txtData.Text, txtDatabaseName.Text, txtUserID.Text, txtpassword.Text);
if (button1.Text == "Connect")
{
//Open Connection
con.Open();
if (con.State == ConnectionState.Executing)
{
lblStatus.Text = "Connecting..........";
}
else if (con.State == ConnectionState.Open)
{
lblStatus.Text = "Connected";
button1.Text = "Disconnect";
btnClear.Enabled = true;
}
}
else
{
con.Close();
lblStatus.Text = "Disconnected";
button1.Text = "Connect";
btnClear.Enabled = false;
}
}
catch (Exception ex)
{
lblStatus.Text = ex.ToString();
}
}
private void btnClear_Click(object sender, EventArgs e)
{
//Clear all Pools.
SqlConnection.ClearAllPools();
lblstatuspool.Text = "Pool Claered";
}