【问题标题】:Entity Framework with SQLite Error: An error occurred while reading from the store provider's data reader带有 SQLite 错误的实体框架:从商店提供者的数据读取器读取时发生错误
【发布时间】:2014-08-08 18:50:14
【问题描述】:
【问题讨论】:
标签:
c#
wpf
entity-framework
sqlite
.net-4.5
【解决方案1】:
问题是由使用相同 DBContext 查询数据库的多个线程引起的。
为每个线程使用不同的 DBContext 可以解决问题。
在我的例子中,我使用 Castle Windsor 将 DBContext 注入到执行查询的类中。
将 DBContext 的生活方式配置为每个线程一个,问题就消失了。
【解决方案2】:
我在 EF6.1 中出现了这个错误,我花了一段时间才弄清楚发生了什么。简化了查询,它起作用了,所以我认为查询中一定发生了一些事情。发现我正在查询一个字符串并在一个 int 上传递一个比较。一旦我改变了 int.toString 一切工作。
Dim OpenOrder = (From p In context.CP_Carthead Where p.SessionID =
MySessionInfo.Current.LeadID.ToString And p.CustomerID = LeadID
And p.Deleted = False And p.PortalID =
TenantID).OrderBy(Function(p) p.OrderID).FirstOrDefault
OrderID = OpenOrder.OrderID
LeadID(我的会话)是一个 int。没有 .ToString 我在上面的帖子中得到错误
【解决方案3】:
我今天在生产应用程序中遇到了这个错误。
这是由于用户出于某些原因将程序及其依赖项安装在启用 OneDrive 的文件夹上造成的。这引发了很多错误,包括这个。希望它能拯救别人的一天。
An unhandled exception occured.An error occurred while reading from the store provider's data reader. See the inner exception for details. at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.HandleReaderException(Exception e)
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.StoreRead()
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)