Copied to clipboard

Flag this post as spam?

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


  • Bo Jacobsen 438 posts 1818 karma points
    Feb 18, 2020 @ 13:08
    Bo Jacobsen
    0

    Database GetTransaction is null the first time accessed after restart

    Hi all.

    Using Umbraco 7.15.3 and everytime i restart my application, then the first time it runs DatabaseContext.Database.GetTransaction() it gets a null exception. If i then skip the error and try to run it again, it works, until next restart.

    First it runs GetAll, then i try to insert a comment into the database with the Insert method.

    // UmbracoServices.Database is equal to UmbracoContext.Current.Application.DatabaseContext.Database
    
    public static void Insert(Comment newEntry)
    {  
        using (var transaction = UmbracoServices.Database.GetTransaction())
        {
            UmbracoServices.Database.Save(newEntry);
    
            var post = UmbracoServices.Database.SingleOrDefault<Post>(newEntry.PostId);
            post.LastReplyDate = newEntry.CreateDate;
            UmbracoServices.Database.Save(post);
    
            transaction.Complete();
        }
    }
    
    public static IEnumerable<Comment> GetAll(int postId)
    {
        var comments = new List<Comment>();
    
        var query = new Sql().Select("*")
            .From(Constants.TableNames.Comments)
            .Where("postId = @0", postId);
    
        return UmbracoServices.Database.Fetch<Comment>(query);
    }
    

    The error i get looks like this. enter image description here

    The database looks like this. enter image description here

    Does anyone have an idea?

  • Bo Jacobsen 438 posts 1818 karma points
    Jul 15, 2020 @ 10:18
    Bo Jacobsen
    0

    We have now updatet to Umbraco Version 7.15.5 and changed UmbracoContext.Current.Application.DatabaseContext.Database to ApplicationContext.Current.DatabaseContext.Database but it's still the same issue.

    We must be doing something wrong, but can't figure it out.

  • Bo Jacobsen 438 posts 1818 karma points
    Jul 16, 2020 @ 12:49
    Bo Jacobsen
    0

    If we remove the GetTransaction() is works. But that's not best practice.

    So any help would still be appreciated.

  • Bo Jacobsen 438 posts 1818 karma points
    Aug 10, 2020 @ 11:00
    Bo Jacobsen
    0

    Has anyone been exposed to this error or have any clue?

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies