Open Audrunas opened 10 years ago
I also got this error several times using BCMS v1.10.0, but with a different entity:
2015-09-15 11:54:50.2506 Application_Error error caught:
Failed to load a CMS page. System.Web.HttpException (0x80004005): Failed to load a CMS page. ---> NHibernate.Exceptions.GenericADOException: could not initialize a collection: [BetterCms.Module.Pages.Models.PageProperties.Categories#b9277de2-9de0-4f3a-9f55-a4b9007702c5][SQL: SELECT categories0_.PageId as PageId1_, categories0_.Id as Id1_, categories0_.Id as Id2_0_, categories0_.Version as Version2_0_, categories0_.IsDeleted as IsDeleted2_0_, categories0_.CreatedOn as CreatedOn2_0_, categories0_.ModifiedOn as ModifiedOn2_0_, categories0_.DeletedOn as DeletedOn2_0_, categories0_.CreatedByUser as CreatedB7_2_0_, categories0_.ModifiedByUser as Modified8_2_0_, categories0_.DeletedByUser as DeletedB9_2_0_, categories0_.PageId as PageId2_0_, categories0_.CategoryId as CategoryId2_0_ FROM bcms_pages.PageCategories categories0_ WHERE (categories0_.IsDeleted = 0) and categories0_.PageId=?] ---> System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)
at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object id, IType type)
--- End of inner exception stack trace ---
at NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object id, IType type)
at NHibernate.Event.Default.DefaultInitializeCollectionEventListener.OnInitializeCollection(InitializeCollectionEvent event)
at NHibernate.Impl.SessionImpl.InitializeCollection(IPersistentCollection collection, Boolean writing)
at NHibernate.Collection.Generic.PersistentGenericBag`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at BetterCms.Module.Pages.ViewModels.Page.RenderPagePropertiesViewModel..ctor(PageProperties page)
at BetterCms.Module.Pages.Helpers.Extensions.RenderPageViewModelExtensions.GetPageModel(RenderPageViewModel viewModel)
at BetterCms.Module.Pages.Mvc.PageHtmlRenderer.RenderingPageMainImageUrlProperty.GetReplacedHtml(StringBuilder stringBuilder, RenderPageViewModel model)
at BetterCms.Module.Root.Mvc.PageHtmlRenderer.PageHtmlRenderer.GetReplacedHtml()
at BetterCms.Module.Root.Mvc.Helpers.LayoutHelper.RenderSectionContents(HtmlHelper htmlHelper, WebPageBase webPage, RenderPageViewModel model)
at BetterCms.Module.Root.Views.Cms.Index.Execute()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at RazorGenerator.Mvc.PrecompiledMvcView.Render(ViewContext viewContext, TextWriter writer)
at BetterCms.Module.Root.Mvc.Helpers.ViewRenderingExtensions.RenderViewToString(CmsControllerBase controller, String viewName, Object model, Boolean enableFormContext)
at BetterCms.Module.Root.Mvc.Helpers.ViewRenderingExtensions.RenderRecursively(CmsControllerBase controller, RenderPageViewModel currentModel, RenderPageViewModel pageModel, HtmlHelper htmlHelper)
at BetterCms.Module.Root.Mvc.Helpers.ViewRenderingExtensions.RenderRecursively(CmsControllerBase controller, RenderPageViewModel currentModel, RenderPageViewModel pageModel, HtmlHelper htmlHelper)
at BetterCms.Module.Root.Mvc.Helpers.ViewRenderingExtensions.RenderPageToString(CmsControllerBase controller, RenderPageViewModel renderPageViewModel)
at BetterCms.Module.Root.Controllers.CmsController.Index()
at BetterCms.Module.Root.Controllers.CmsController.Index()
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<>c__DisplayClass2a.<BeginInvokeAction>b__20()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
at System.Web.Mvc.Controller.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) could not initialize a collection: [BetterCms.Module.Pages.Models.PageProperties.Categories#b9277de2-9de0-4f3a-9f55-a4b9007702c5][SQL: SELECT categories0_.PageId as PageId1_, categories0_.Id as Id1_, categories0_.Id as Id2_0_, categories0_.Version as Version2_0_, categories0_.IsDeleted as IsDeleted2_0_, categories0_.CreatedOn as CreatedOn2_0_, categories0_.ModifiedOn as ModifiedOn2_0_, categories0_.DeletedOn as DeletedOn2_0_, categories0_.CreatedByUser as CreatedB7_2_0_, categories0_.ModifiedByUser as Modified8_2_0_, categories0_.DeletedByUser as DeletedB9_2_0_, categories0_.PageId as PageId2_0_, categories0_.CategoryId as CategoryId2_0_ FROM bcms_pages.PageCategories categories0_ WHERE (categories0_.IsDeleted = 0) and categories0_.PageId=?] NHibernate.Exceptions.GenericADOException: could not initialize a collection: [BetterCms.Module.Pages.Models.PageProperties.Categories#b9277de2-9de0-4f3a-9f55-a4b9007702c5][SQL: SELECT categories0_.PageId as PageId1_, categories0_.Id as Id1_, categories0_.Id as Id2_0_, categories0_.Version as Version2_0_, categories0_.IsDeleted as IsDeleted2_0_, categories0_.CreatedOn as CreatedOn2_0_, categories0_.ModifiedOn as ModifiedOn2_0_, categories0_.DeletedOn as DeletedOn2_0_, categories0_.CreatedByUser as CreatedB7_2_0_, categories0_.ModifiedByUser as Modified8_2_0_, categories0_.DeletedByUser as DeletedB9_2_0_, categories0_.PageId as PageId2_0_, categories0_.CategoryId as CategoryId2_0_ FROM bcms_pages.PageCategories categories0_ WHERE (categories0_.IsDeleted = 0) and categories0_.PageId=?] ---> System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)
at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object id, IType type)
--- End of inner exception stack trace ---
at NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object id, IType type)
at NHibernate.Event.Default.DefaultInitializeCollectionEventListener.OnInitializeCollection(InitializeCollectionEvent event)
at NHibernate.Impl.SessionImpl.InitializeCollection(IPersistentCollection collection, Boolean writing)
at NHibernate.Collection.Generic.PersistentGenericBag`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at BetterCms.Module.Pages.ViewModels.Page.RenderPagePropertiesViewModel..ctor(PageProperties page)
at BetterCms.Module.Pages.Helpers.Extensions.RenderPageViewModelExtensions.GetPageModel(RenderPageViewModel viewModel)
at BetterCms.Module.Pages.Mvc.PageHtmlRenderer.RenderingPageMainImageUrlProperty.GetReplacedHtml(StringBuilder stringBuilder, RenderPageViewModel model)
at BetterCms.Module.Root.Mvc.PageHtmlRenderer.PageHtmlRenderer.GetReplacedHtml()
at BetterCms.Module.Root.Mvc.Helpers.LayoutHelper.RenderSectionContents(HtmlHelper htmlHelper, WebPageBase webPage, RenderPageViewModel model)
at BetterCms.Module.Root.Views.Cms.Index.Execute()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at RazorGenerator.Mvc.PrecompiledMvcView.Render(ViewContext viewContext, TextWriter writer)
at BetterCms.Module.Root.Mvc.Helpers.ViewRenderingExtensions.RenderViewToString(CmsControllerBase controller, String viewName, Object model, Boolean enableFormContext)
at BetterCms.Module.Root.Mvc.Helpers.ViewRenderingExtensions.RenderRecursively(CmsControllerBase controller, RenderPageViewModel currentModel, RenderPageViewModel pageModel, HtmlHelper htmlHelper)
at BetterCms.Module.Root.Mvc.Helpers.ViewRenderingExtensions.RenderRecursively(CmsControllerBase controller, RenderPageViewModel currentModel, RenderPageViewModel pageModel, HtmlHelper htmlHelper)
at BetterCms.Module.Root.Mvc.Helpers.ViewRenderingExtensions.RenderPageToString(CmsControllerBase controller, RenderPageViewModel renderPageViewModel)
at BetterCms.Module.Root.Controllers.CmsController.Index()
There is already an open DataReader associated with this Command which must be closed first. System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)
at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object id, IType type)
I think we have fixed this issue, this was open graph bug it is fixed in 1.9.3+ and 1.10.3+ versions https://github.com/devbridge/BetterCMS/wiki/Release-Notes.
In our project Open Graph module is not used and we are still getting this issue.
http://stackoverflow.com/questions/4867602/entity-framework-there-is-already-an-open-datareader-associated-with-this-comma/4868569 Second part of the comment can be relevant to CMS (regarding iteration over lazy load).
Complicated places, because of lazy load: https://github.com/devbridge/BetterCMS/blob/master/Modules/BetterCms.Module.Pages/ViewModels/Page/RenderPagePropertiesViewModel.cs#L45 https://github.com/devbridge/BetterCMS/blob/master/Modules/BetterCms.Module.Pages/ViewModels/Page/RenderPageCategoryViewModel.cs#L16
Release has fix not to load categories and tags if SmartTags feature is not used in the project https://www.nuget.org/packages/BetterCMS/1.10.4 , but this fix just hides issue a little bit deeper.
No steps to reproduce. Occurs on few different web projects Occurs occasionally.
One of solutions: http://sradack.blogspot.hu/2007/07/enable-mars-on-your-nhibernate.html The same problem has Orchard CMS: https://orchard.codeplex.com/workitem/20544
Need to investigate, reproduce, if possible. Review logs of all staging / production / other projects, maybe there is such a bug found.