tags:

views:

46

answers:

1

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");
A: 

I'm not sure what the issue is – I just read the source code to the C# client and C# implementation of sqlite, and there's nothing obvious – so maybe you just need to wait a few seconds for the OS to finish writing things back to disk before it is all ready to be deleted?

Of course, if it isn't that much data then you should just use an in-memory database. Why bother the filesystem with the data if you don't have to? You need this connection string:

Data Source=file::memory:;Version=3;
Donal Fellows
even after waiting several seconds or minutes the file isn`t unlocked.the listing was only a simplification of the actual code. but thank you for that hint.
Chris Ortiz
Well, it beats “Dude, that should work” which was what I was going to write first off. :-)
Donal Fellows