Entity Framework with SQLite Error: An error occurred while reading from the store provider's data reader
Solution 1
The problem was caused by multiple thread that query the db using the same DBContext.
Using a different DBContext for each thread solve the problem.
In my case I was using Castle Windsor to inject the DBContext into the class that perform the query. Configuring the lifestyle of the DBContext to one per thread the problem has gone.
Solution 2
I had this error occur in EF6.1 and took me a while to figure out what was going on. 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. once I changed the int.toString all worked.
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. without the .ToString I get the error in the above post
Comments
-
abrfra over 2 years
I'm using SQLite 1.0.89 with EF 5 .NET Framework 4.5 on VS2013 in a WPF application in C#. The DB size is not big and the table that the program use contain max 1000 row.
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"}
Other time the inner exception is:
Connection was closed, statement was terminated
Another time i found:
unknown error\r\nno connection handle available
I found this article searching:
Parallel.Foreach loop creating multiple db connections throws connection errors?
SQL Server CE database size issue
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.
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:
public List<Product> ProductList { get { return DBContext.Products.ToList(); } }