There is already an open DataReader associated with this Command which must be closed
I tried to add support for multi levels categories by adding ParentCategoryID to the Categories table and make necessary modification to stored procedures, DAL and BLL.
but now i get this error "There is already an open DataReader associated with this Command which must be closed" at ExecuteReader(DbCommand cmd, CommandBehavior behavior)
Category.cs
public static List<Category> GetCategories()
{
List<Category> categories = null;
string key = "Articles_Categories";
if (BaseArticle.Settings.EnableCaching && BizObject.Cache[key] != null)
{
categories = (List<Category>)BizObject.Cache[key];
}
else
{
List<CategoryDetails> recordset = SiteProvider.Articles.GetCategories();
categories = GetCategoryListFromCategoryDetailsList(recordset);
BaseArticle.CacheData(key, categories);
}
return categories;
}
SqlArticlesProvider.cs
public override List<CategoryDetails> GetCategories()
{
using (SqlConnection cn = new SqlConnection(this.ConnectionString))
{
SqlCommand cmd = new SqlCommand("WS_Articles_GetCategories", cn);
cmd.CommandType = CommandType.StoredProcedure;
cn.Open();
return GetCategoryCollectionFromReader(ExecuteReader(cmd) );
}
}
DataAccess.cs
protected IDataReader ExecuteReader(DbCommand cmd)
{
return ExecuteReader(cmd, CommandBehavior.Default);
}
protected IDataReader ExecuteReader(DbCommand cmd, CommandBehavior behavior)
{
return cmd.ExecuteReader(behavior);
}
|