SQLite keeps the database locked even after the connection is closed

后端 未结 12 1307
故里飘歌
故里飘歌 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 02:51

    As said earlier SQLite objects must be destroyed. However, there is a strange behavior: connection must be open during a call Dispose on commands. For example:

    using(var connection = new SqliteConnection("source.db"))
    {
        connection.Open();
        using(var command = connection.CreateCommand("select..."))
        {
            command.Execute...
        }
    }
    

    works fine, but:

    using(var connection = new SqliteConnection("source.db"))
    {
        connection.Open();
        using(var command = connection.CreateCommand("select..."))
        {
            command.Execute...
            connection.Close();
        }
    }
    

    gives the same file lock

提交回复
热议问题