Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Diego 25 posts 156 karma points
    Aug 29, 2023 @ 11:04
    Diego
    0

    SQLite Error 6: database table is locked

    Hello everyone! In project i need to create a custom tables, so i followed this guide. https://docs.umbraco.com/umbraco-cms/tutorials/getting-started-with-entity-framework-core

    The problem arises at the end of the guide, when making a POST type call, on SaveChangesAsync() I get this error: "SQLite Error 6: database table is locked"

    Below is the portion of sample code in the guide.

    [HttpPost]
    public async Task InsertComment(BlogComment comment)
    {
        using IEfCoreScope<BlogContext> scope = _efCoreScopeProvider.CreateScope();
    
        await scope.ExecuteWithContextAsync<Task>(async db =>
        {
            db.BlogComments.Add(comment);
            await db.SaveChangesAsync();
        });
    
        scope.Complete();
    }
    

    Thanks.

  • Mark Jarvis 5 posts 116 karma points
    Sep 09, 2023 @ 22:21
    Mark Jarvis
    100

    Hey Diego,

    I was running into this same issue and I've been able to work past it using a non-simplified using statement. I'm not sure why it works, but I have seen this in Core with other methods where using the simplified using throws unexpected errors. But anyway this code should work for you:

    [HttpPost]
    public async Task InsertComment(BlogComment comment)
    {
        using IEfCoreScope<BlogContext> scope = _efCoreScopeProvider.CreateScope())
        {
    
            await scope.ExecuteWithContextAsync<Task>(async db =>
            {
                db.BlogComments.Add(comment);
                await db.SaveChangesAsync();
            });
    
            scope.Complete();
        }
    }
    

    Hope that helps!

    --Mark

  • Diego 25 posts 156 karma points
    Sep 11, 2023 @ 07:49
    Diego
    1

    Thank you very much Mark!

  • Mark Jarvis 5 posts 116 karma points
    Sep 11, 2023 @ 12:32
    Mark Jarvis
    0

    Anytime, glad it helped!

  • Lidia 1 post 71 karma points
    Oct 26, 2023 @ 10:11
    Lidia
    0

    Did you find any solution about this issue?

  • Iliyan 6 posts 76 karma points
    Feb 11, 2024 @ 13:53
    Iliyan
    0

    I'd like to know the answer to that question as well.

    Could it be that the problem is the usage of lock statements and not SemaphoreSlim.WaitAsync() and .Release() ?

    Lock statement usage

Please Sign in or register to post replies

Write your reply to:

Draft