Shouldn`t the following statement be autocommited? I get an IOException trying to delete the file after executing the query.
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");
I'm late to the party, but I had to:
GC.WaitForPendingFinalizers();
GC.Collect();
Prior to calling File.Delete().
Isn't the SQLiteCommand also Dispose(able)? The connection might not close because you haven't closed the command yet. I'd use a using for that too.
You have to dispose of every SQLiteConnection, SQLiteCommand and SQLiteDataReader once you are done using it. Simply create the SQLiteCommand within a "using" block and the problem will go away.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With