我有一份网络表格,显示GridView中的记录清单,并检查你可以大规模删除记录。 法典本身是直截了当的:
protected void btnDelete_Click(object sender, EventArgs e)
{
int i = 0;
try
{
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("ID");
if (cb != null && cb.Checked)
{
int profileID = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
Profile profile = new Profile(profileID); //instantiate profile
profile.Delete(); //call delete method
i++;
}
}
if (i > 0)
{
//report success to UI
}
}
catch (Exception ex)
{
//report error to UI
}
}
在图像构造中,它通过开放连接、开放数据读物,然后确定物体的特性,对物体进行水化。 我对我的代码中的<编码>(>>各条条条有同感,因此每条条条条条条条条条条条条条条有点:
using (SQLHelper db = new SQLHelper())
{
db.AddParameterToSQLCommand("@ProfileID", SqlDbType.Int);
db.SetSQLCommandParameterValue("@ProfileID", id);
using (SqlDataReader dr = db.GetReaderByCmd("up_GetProfile"))
{
if (dr.Read())
{
_profileID = id;
if (!dr.IsDBNull(0))
ProfileName = dr.GetString(0);
//... and so on
return true;
}
else
{
return false;
}
}
}
一位数据校正像我的助手班一样,实施“可变”方案,而主子则认为:
public void Dispose()
{
try
{
//Clean Up Connection Object
if (mobj_SqlConnection != null)
{
if (mobj_SqlConnection.State != ConnectionState.Closed)
{
mobj_SqlConnection.Close();
}
mobj_SqlConnection.Dispose();
}
//Clean Up Command Object
if (mobj_SqlCommand != null)
{
mobj_SqlCommand.Dispose();
}
}
catch (Exception ex)
{
throw new Exception("Error disposing data class." + Environment.NewLine + ex.Message);
}
}
When I step through my code I see that connections are always being opened and closed correctly, my stack is never more than five or six calls deep (I m not running into any recursion problems) I have confirmed that all my data access code is correctly wrapped in using blocks yet my connections aren t being released back to the pool. Instead I get this error:
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.
This happens in a dedicated app pool with a single user effecting a delete on 10+ profiles. It seems like I m doing everything correctly but I am at a loss as to why connections are not being released back to the pool. At most there should only ever be two connections open by the executing thread, both of which should (and do!) dispose when they go out of scope.
I m clearly doing something wrong but can t for the life of me figure out what.