I'm using SQLite for .Net and EntityFramework from .Net Framework 4.0. Everything was ok until I moved from SQLite v.1.0.79.0 to v.1.0.86.0. From that time code like this
using (var context = new EntityContent(sqliteConnectionString))
{
context.ExecuteStoreCommand(mySqlScriptString);
/*
* or do some stuff with context entities and call context.SaveChanges()
*/
}
deleteSQLiteDbFile(getDbFilePath(sqliteConnectionString)); // <-- here is the error
throws the error System.IO.IOException: "The process cannot access the file 'mydatabase.dat' because it is being used by another process."
It's all because of moving to the new sqlite3_close_v2() API in SQLite v.1.0.82.0 (see this). As you can see in this ticket you should properly dispose all sqlite commands and readers. But EF 4 doesn't do it (at least in the .net framework 4 version). For instance, see ObjectContent.ExecuteStoreCommand method. It implicitly creates a command from SQLite connection and doesn't dispose it.
Yes, I can write my own executeStoreCommand(ObjectContent context, string script, params object[] parameters) method with proper command disposing but what to do with context.SaveChanges()?
Does anybody know if it fixed in next releases of EF or SQLite? Or may be there are any workarounds?