Copied to clipboard

Flag this post as spam?

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


  • jacky joy 2 posts 72 karma points
    Aug 04, 2021 @ 13:28
    jacky joy
    0

    Database GetTransaction is null the first time accessed after the restart ?.

    Hello,

    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? https://myhrkp.online/ https://flvslogin.online/ https://pointclickcarecna.online/ https://theranestlogin.online/

    thanks jackyjoy

Please Sign in or register to post replies

Write your reply to:

Draft