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);
}
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.
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.
The error i get looks like this.
The database looks like this.
Does anyone have an idea?
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.
If we remove the
GetTransaction()
is works. But that's not best practice.So any help would still be appreciated.
Has anyone been exposed to this error or have any clue?
is working on a reply...
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.