gpt4 book ai didi

entity-framework - Entity Framework 在datareader关闭时调用 'Read'

转载 作者:行者123 更新时间:2023-12-03 11:47:58 24 4
gpt4 key购买 nike

这个问题不太可能对任何 future 的访客有帮助;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于互联网的全局受众。如需帮助使这个问题更广泛适用,visit the help center .




9年前关闭。




我的网络主机出现故障。现在终于又恢复了,我还不知道技术人员修复了什么。
问题是现在我收到错误:

Calling 'Read' when the data reader is closed is not a valid operation. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Calling 'Read' when the data reader is closed is not a valid operation.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: Calling 'Read' when the data reader is closed is not a valid operation.]
System.Data.Common.Internal.Materialization.Shaper`1.StoreRead() +93
System.Data.Common.Internal.Materialization.SimpleEnumerator.MoveNext() +30
System.Linq.Enumerable.Single(IEnumerable`1 source) +119
System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__2(IEnumerable`1 sequence) +5
System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle(IEnumerable`1 query, Expression queryRoot) +25
System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute(Expression expression) +43
System.Linq.Queryable.Count(IQueryable`1 source) +240
BusinessLayer.Car.GetCarCount() in xxx
UserControls_SiteInfo.Page_Load(Object sender, EventArgs e) +225
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

我没有改变任何东西,所以它可能是一些权限吗?我仍然可以使用相同的凭据登录到我的数据库,因此它不是登录信息。有人有想法吗?

更新:我发现当我尝试将 IQuery 转换为列表时出现错误。我以前从未收到过错误,这是否给你们任何人一个可能是错误的线索?

最佳答案

Entity Framework 使用惰性求值。这意味着在您创建数据库时实际上并未对数据库执行查询,而是在您实际需要数据时执行查询。因此,当您处理查询时,数据上下文必须仍处于打开状态。

将查询转换为 IList 将强制执行查询。如果此时关闭数据上下文,您将收到这样的错误。

如果您没有更改任何代码,我无法解释为什么您之前没有收到此信息,但这就是我要查看的内容。

也许发布您的代码,这可能有助于诊断问题。

关于entity-framework - Entity Framework 在datareader关闭时调用 'Read',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/972025/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com