c# - How to close a sqlite file opened with System.Data.SQLite and DbContext? -
in my ef6 recreation of this walkthrough creating , accessing sqlite database using system.data.sqlite, found access database leaves file handle open database file long after i've disposed of disposable object created: dbcontext.
this prevents me deleting database file when i'm done (e.g. @ conclusion of unit test, or when user of app requests it).
you can see how simple use of dbcontext
, how file.delete
after closing fails:
using (var context = new chinookcontext()) { var artists = in context.artists a.name.startswith("a") orderby a.name select a; foreach (var artist in artists) { console.writeline(artist.name); } } // i've disposed of dbcontext. handles sqlite database file should // have been released now. // yet, next line fails because file still locked. file.delete("chinook_sqlite_autoincrementpks.sqlite");
(full project context on github)
any ideas of i'm missing in order close file handle?
btw, i'm aware of faq #22 on file locks being released when dispose of command, data reader, etc., haven't opened of these myself don't know how can dispose of them.
Comments
Post a Comment