I have a slight problem that I'm trying to solve. I am using SQLite database and i created my database Schedule.db automatically when application starts for the first time(if .db does not already exists).
On a button_click I want to delete it so I can create new one when I start my application again.
The problem is, every time I try to delete it I get an error:
"Additional information: The process cannot access the file '/filePath.../Scheduler.db' because it is being used by another process."
I understand that I can't delete it because my application is already using it but is there any solution to my current problem?
string databasePath = AppDomain.CurrentDomain.BaseDirectory + "Scheduler.db";
if (MessageBox.Show("Do you want to delete database: [Scheduler.db]?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes) == MessageBoxResult.Yes)
{
if (File.Exists(databasePath))
{
SQLiteConnection connectionSqlLIte = new SQLiteConnection(@"Data Source=Scheduler.db;Version=3;");
connectionSqlLIte. Close();
File.Delete(databasePath);
MessageBox.Show("Database deleted: [Scheduler] ");
Application.Current.Shutdown();
}
else
{
MessageBox.Show("There is no database: [Scheduler]!");
}
}