Connection being closed?
Hi
I have been looking at some of the methods in the SQL Provider classes which interact with the database. My query is, I dont see where the connection to the database is closed. I can see when its opened, but not closed. Some examples:
public override bool DeleteCategory(int categoryID)
{
using (SqlConnection cn = new SqlConnection(this.ConnectionString))
{
SqlCommand cmd = new SqlCommand("tbh_Articles_DeleteCategory", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@CategoryID", SqlDbType.Int).Value = categoryID;
cn.Open();
int ret = ExecuteNonQuery(cmd);
return (ret == 1);
}
}
/// <summary>
/// Returns a collection with all the categories
/// </summary>
public override List<CategoryDetails> GetCategories()
{
using (SqlConnection cn = new SqlConnection(this.ConnectionString))
{
SqlCommand cmd = new SqlCommand("tbh_Articles_GetCategories", cn);
cmd.CommandType = CommandType.StoredProcedure;
cn.Open();
return GetCategoryCollectionFromReader(ExecuteReader(cmd) );
}
}
/// <summary>
/// Retrieves all articles for the specified category
/// </summary>
public override List<ArticleDetails> GetArticles(int categoryID, int pageIndex, int pageSize)
{
using (SqlConnection cn = new SqlConnection(this.ConnectionString))
{
SqlCommand cmd = new SqlCommand("tbh_Articles_GetArticlesByCategory", cn);
cmd.Parameters.Add("@CategoryID", SqlDbType.Int).Value = categoryID;
cmd.Parameters.Add("@PageIndex", SqlDbType.Int).Value = pageIndex;
cmd.Parameters.Add("@PageSize", SqlDbType.Int).Value = pageSize;
cmd.CommandType = CommandType.StoredProcedure;
cn.Open();
return GetArticleCollectionFromReader(ExecuteReader(cmd), false);
}
}
|