SQlite likes to have a single opened connection.
Massive is managing the connections correctly however it leaves the ExecuteReader
"open" in the Query method which can cause troubles:
Robert Simpson wrote:
Leaving readers open could cause issues. Those won't get cleaned up until the lazy garbage collector gets around to it. It'd certainly be better in any case to have using() statements around your readers at the very least. The following objects use unmanaged resources that the garbage collector will be lazy about cleaning up:
SQLiteCommand, SQLiteConnection, SQLiteDataReader, and possibly SQLiteTransaction if I recall correctly.
So put an using
around the ExecuteReader()
in the Query
method and it should work fine:
public virtual IEnumerable<dynamic> Query(string sql, params object[] args)
{
using (var conn = OpenConnection())
{
using (var rdr = CreateCommand(sql, conn, args).ExecuteReader())
{
while (rdr.Read())
{
yield return rdr.RecordToExpando(); ;
}
}
}
}
Some notes and other workarounds which not requires changing the Massive source:
you can enable connection pooling in SQLite with
Pooling
setting:connectionString="Data Source=test.db;Version=3;Pooling=True;Max Pool Size=100;"
the
Query
usually works right if it the reads all the data from the reader. But you usedFirst()
which combined with theyield return
left the reader open. So if you evaluate the query withToArray()
it will also work:var firstCustomerName= customers.ToArray().First().FirstName;