abrfra
abrfra

Reputation: 654

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#. 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();
    }
}

Upvotes: 5

Views: 38144

Answers (3)

Arthur Attout
Arthur Attout

Reputation: 2916

I experienced this error today on a production application.

This was caused by a user, for some reasons, installing the program and its dependencies on a OneDrive-enabled folder. This triggered a whole lot of bugs including this one. Hope it saves someone's day.

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)

Upvotes: 1

ransems
ransems

Reputation: 671

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

Upvotes: 1

abrfra
abrfra

Reputation: 654

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.

Upvotes: 8

Related Questions