SQLite keeps the database locked even after the connection is closed

后端 未结 12 1354
故里飘歌
故里飘歌 2020-11-30 02:33

I\'m using System.Data.SQLite provider in an ASP.NET application (framework 4.0). The issue I\'m running into is that when I INSERT something in a table in the SQLite databa

12条回答
  •  悲哀的现实
    2020-11-30 03:12

    I found edymtt's answer right about blaming TableAdapters / Datasets, but instead of modifying the every time re-generated TableAdapter codefile, I found an other solution: to manually call .Dispose on the TableAdapter's child elements. (In .NET 4.5, latest SQLite 1.0.86)

    using (var db = new testDataSet())
    {
        using (testDataSetTableAdapters.UsersTableAdapter t = new testDataSetTableAdapters.UsersTableAdapter())
        {
            t.Fill(db.Users);
            //One of the following two is enough
            t.Connection.Dispose(); //THIS OR
            t.Adapter.Dispose();    //THIS LINE MAKES THE DB FREE
        }
        Console.WriteLine((from x in db.Users select x.Username).Count());
    }
    

提交回复
热议问题