【发布时间】:2009-06-09 19:24:35
【问题描述】:
我的虚拟主机出现故障。现在终于又恢复了,我还不知道技术人员修复了什么。 问题是我现在收到错误:
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 转换为列表时出现错误。我以前从未收到过错误,这是否让你们知道可能出了什么问题?
【问题讨论】:
-
执行直接 SQL 查询时会发生什么? (不使用 linq-to-sql)
-
我发现这是我的数据库或我的虚拟主机网络的错误,因此它与实体框架本身无关。
-
将
IEnumerable更改为IList为我解决了这个问题我正在从存储过程中返回一个复杂对象 -
如果模型中遗漏了属于关系一部分的表,也会发生此错误。即使您不打算使用特定表,如果它与您正在使用的表有关系,也应该将其引入。
标签: entity-framework