SQLite lock file, although the connection is closed

Should the following statement be autocomposite ? I get an IOException trying to delete a file after executing the request.

using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "data\\test.db;Version=3;"))
{
    connection.Open();
    SQLiteCommand command = new SQLiteCommand("CREATE TABLE IF NOT EXISTS test (id INTEGER)", connection);
    command.ExecuteNonQuery();
}

//throwing an IOException
File.Delete(AppDomain.CurrentDomain.BaseDirectory + "data\\test.db");
+3
source share
4 answers

I'm late to the party, but I had to:

GC.WaitForPendingFinalizers();
GC.Collect();

Before calling File.Delete ().

+3
source

Is SQLiteCommand Dispose (capable)? The connection may not close because you have not closed the command. I would also use this to use.

+1
source

, : # # sqlite - , , , , ?

Of course, if this is not so much data, you should just use the database in memory. Why bother file system data if you don't need it? You need this connection string:

Data Source=file::memory:;Version=3;
0
source

Did you try to close the connection after executing the request?

connection.Close();

0
source

Source: https://habr.com/ru/post/1744300/


All Articles