c# - DataContext accessed after Dispose in render pages/controls -


i'm randomly getting "datacontext accessed after dispose" errors on aspx , ascx pages/controls. there general rule shouldn't calling methods inline on pages use datacontexts?

i'm presuming time page renders , calls method datacontext has been disposed?

e.g. on default.aspx

<%= currentcontent.gettext("intro") %> 

currentcontent database object referred in default.aspx.cs

assuming using this

using (mydbcontext ctx = new mydbcontext()) {     return r in ctx.table select r; } 

deferred execution happening you. query not execute right , there, , running when returned enumerator used - in case, after using block disposes of context. if want sure doesn't happen, either change query pattern

using (mydbcontext ctx = new mydbcontext()) {     return (from r in ctx.table select r).tolist(); } 

or change disposal methods. tend tying lifetime of context enclosing object, in case asp.net page object. make context member variable , dispose of in page.dispose


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -