简体   繁体   English

带有SQLite错误的实体框架:从商店提供商的数据读取器读取时发生错误

[英]Entity Framework with SQLite Error: An error occurred while reading from the store provider's data reader

I'm using SQLite 1.0.89 with EF 5 .NET Framework 4.5 on VS2013 in a WPF application in C#. 我正在使用SQLite 1.0.89和VS2013上的EF 5 .NET Framework 4.5在C#中的WPF应用程序中。 The DB size is not big and the table that the program use contain max 1000 row. DB大小不大,程序使用的表包含最多1000行。

using the program I found this error often: 使用该程序我经常发现这个错误:

An error occurred while reading from the store provider's data reader. 从商店提供商的数据阅读器读取时发生错误。 See the inner exception for details. 有关详细信息,请参阅内部异常

the inner exception is : 内在的例外是:

{"library routine called out of sequence\\r\\nnot an error"} {“库程序不按顺序调用\\ r \\ n \\ n错误”}

Other time the inner exception is: 其他时间内部异常是:

Connection was closed, statement was terminated 连接已关闭,声明已终止

Another time i found: 我又发现了一次:

unknown error\\r\\nno connection handle available 未知错误\\ r \\ nno连接句柄可用

I found this article searching: 我找到这篇文章搜索:

Parallel.Foreach loop creating multiple db connections throws connection errors? Parallel.Foreach循环创建多个数据库连接会引发连接错误?

SQL Server CE database size issue SQL Server CE数据库大小问题

but no one solve my problem. 但没有人解决我的问题。

The query that the program do IS NOT inside a loop, but are single query performed when button is pressed on the UI but i noticed that the error happens more often (bun not only) when I press the query button a lot of time faster. 程序执行的查询不在循环内,但是当在UI上按下按钮时执行单个查询,但我注意到当我按下查询按钮更快的时间时,错误更频繁地发生(不仅是发髻)。

Other thing. 其他的事情。 The error happens more often (but again not only) when the DB Context is access via a properties istead of a method example: 当DB Context通过属性访问而不是方法示例时,错误更频繁地发生(但不仅仅是)

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

The problem was caused by multiple thread that query the db using the same DBContext. 该问题是由使用相同DBContext查询数据库的多个线程引起的。

Using a different DBContext for each thread solve the problem. 为每个线程使用不同的DBContext解决问题。

In my case I was using Castle Windsor to inject the DBContext into the class that perform the query. 在我的例子中,我使用Castle Windsor将DBContext注入执行查询的类中。 Configuring the lifestyle of the DBContext to one per thread the problem has gone. 将DBContext的生活方式配置为每个线程一个问题已经消失。

I had this error occur in EF6.1 and took me a while to figure out what was going on. 我在EF6.1中发生了这个错误,并花了一些时间来弄清楚发生了什么。 Simplified the query, and it worked, so I figured something must be going on in the query. 简化了查询,并且它有效,所以我想在查询中必须要进行一些操作。 Found out I was querying a string and passing a compare on an int. 发现我正在查询字符串并在int上传递比较。 once I changed the int.toString all worked. 一旦我改变了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 (my Session) is an int. LeadID(我的会话)是一个int。 without the .ToString I get the error in the above post 没有.ToString我在上面的帖子中得到了错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM