最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

windows - How can I force my own app to release a lock over its SQLite DB file? - Stack Overflow

programmeradmin1浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论