【问题标题】: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 应用程序中在 VS2013 上使用 SQLite 1.0.89 和 EF 5 .NET Framework 4.5。 DB大小不大,程序使用的表最多包含1000行。

使用程序我经常发现这个错误:

从商店提供商的数据读取器读取时出错。 有关详细信息,请参阅内部异常。

内部异常是:

{"调用的库例程乱序\r\n不是错误"}

其他时候内部异常是:

连接已关闭,语句已终止

我又找到了一次:

未知错误\r\n没有可用的连接句柄

我在搜索中发现了这篇文章:

Parallel.Foreach loop creating multiple db connections throws connection errors?

SQL Server CE database size issue

但是没有人解决我的问题。

程序执行的查询不在循环内,而是在 UI 上按下按钮时执行的单个查询,但我注意到当我多次按下查询按钮时错误发生的频率更高(不仅是面包)时间更快。

其他的。当通过属性而不是方法示例访问 DB 上下文时,该错误更频繁地发生(但不仅如此):

public List<Product> ProductList
{
get {
      return DBContext.Products.ToList();
    }
}

【问题讨论】:

    标签: 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)
        

        【讨论】:

          猜你喜欢
          • 2023-03-08
          • 1970-01-01
          • 1970-01-01
          • 2013-11-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-05-17
          相关资源
          最近更新 更多