I'm trying to close a database and then delete the database file. After executing procedures like:
string sql = @"SELECT * FROM comments WHERE name=@name";
var command = new SQLiteCommand(sql, m_dbConnection);
command.Parameters.Add(new SQLiteParameter("@name", name));
SQLiteDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
return reader.GetString(1);
}
else
return "";
I initiate a method the starts:
m_dbConnection.Close();
if (System.IO.File.Exists("MyDatabase.sqlite"))
System.IO.File.Delete("MyDatabase.sqlite");
This latter code, however, generates an IOException
:
The process cannot access the file [filepath] because it is being used by another process.
The error message seems self-explanatory (and I did look at this SO post on the topic), but I guess I don't understand how to stop using the file so I can delete it.