I am working on a MAUI application which uses sqlite-net-pcl as its ORM. When I try to delete the DB file from the app (System.IO.File.Delete(dbFilePath)) I get the following exception on Windows: The process cannot access the file 'dbFilePath' because it is being used by another process.
The API of this ORM doesn't seem to offer any commands to forcefully close any connections to the DB file.
I've tried using:
GC.Collect();
GC.WaitForPendingFinalizers(); no luck here.
The async connections used in the app, I do the following:
try
{
dbConnection = new SQLiteAsyncConnection(DBConnectionString);
await dbConnection.<do whatever in the DB>;
}
catch (Exception ex)
{
ParentPage?.DisplayAlert("Error", $"{ex.Message}", "Close");
return false;
}
finally
{
await dbConnection.CloseAsync();
}
For the synchronous connections I don't have full control over since that's being managed by another department and they provide me with a nuget package so, maybe the problem is there but I cannot do much about it.
I know for a fact the file is locked by my own app, I used 3rd party tools to identify which process is locking the file and it's my app.
Any ideas on how to force a file lock release here?