samedi 25 avril 2015

How to properly close a SQLite connection in C#?

I have the following code in my project:

using (var db = new SQLiteConnection("Data Source=" + dbPath + ";Version=3;"))
        {
            using (var con = new DataContext(db))
            {
                var table = con.GetTable<MyTable>();
                var list = table.ToList();
            }
        }

return null;

One would expect that once the code reaches the "return null" statement the db file will be released.

But further examination with Process Explorer shows that the db file is still being kept open.

More over, the db file is being kept open for the entire execution of the process.

In order to stop locking the db file I must close the process.

How can I solve this situation ? What am I not releasing properly ?

Aucun commentaire:

Enregistrer un commentaire