J
Jake K
I have a system timer that elapses every 10 seconds and must execute every
ten seconds. Basically every 10 seconds I need to insert into a table. The
following code, however, causes a "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." error at cn.open() after about 2 minutes of executing.
private void LogToTable(string var1)
{
SqlConnection cn;
cn = new SqlConnection(cnString);
SqlCommand cmd;
try
{
cn.Open();
cmd = new SqlCommand("insert into table_name(col1) values('"
+ var1 + "')", cn);
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message.ToString()));
}
finally
{
if (cn.State == ConnectionState.Open)
cn.Close();
}
}
Any ideas why the connection is not immediately closing in the finally
block? sp_who reports many, many, many connections that never get returned
(or so it appears). This app must run every day all day, every x numberof
seconds.
"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."
at cn.open
ten seconds. Basically every 10 seconds I need to insert into a table. The
following code, however, causes a "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." error at cn.open() after about 2 minutes of executing.
private void LogToTable(string var1)
{
SqlConnection cn;
cn = new SqlConnection(cnString);
SqlCommand cmd;
try
{
cn.Open();
cmd = new SqlCommand("insert into table_name(col1) values('"
+ var1 + "')", cn);
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message.ToString()));
}
finally
{
if (cn.State == ConnectionState.Open)
cn.Close();
}
}
Any ideas why the connection is not immediately closing in the finally
block? sp_who reports many, many, many connections that never get returned
(or so it appears). This app must run every day all day, every x numberof
seconds.
"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."
at cn.open