I'm using the Umbraco Persistence library to store data in custom tables within the Umbraco database.
I've built a service layer to handle the business logic during CRUD operations. For one such operation I need to wrap several commands inside a transaction.
However, when I call the UmbracoDatabase.BeginTransaction() method, it throws a System.NullReferenceException error. Having inspected the code, I think it's the connection that is null.
It's weird though because I am passing in an existing UmbracoDatabase from an UmbracoAuthorizedJsonController: DatabaseContext.Database. I've also tried calling OpenSharedConnection() - to no avail.
I've tried to identify the source code on GitHub but I can't actually find the 'UmbracoDatabase' class anywhere, nor can I find any documentation.
Is anyone able to shed any light? Am I being silly?
Unfortunately it's still throwing the same null exception. It's odd because if I remove the transaction code, calls to the DB work as expected. It's as if the connection / transaction is created at SQL run-time, for example when executing
Db.SingleOrDefault()
or
Db.Page()
It's good to know that method exists though, I had missed that earlier.
Umbraco Persistence Transactions
Hola amigos,
I'm using the Umbraco Persistence library to store data in custom tables within the Umbraco database.
I've built a service layer to handle the business logic during CRUD operations. For one such operation I need to wrap several commands inside a transaction.
However, when I call the UmbracoDatabase.BeginTransaction() method, it throws a System.NullReferenceException error. Having inspected the code, I think it's the connection that is null.
It's weird though because I am passing in an existing UmbracoDatabase from an UmbracoAuthorizedJsonController: DatabaseContext.Database. I've also tried calling OpenSharedConnection() - to no avail.
I've tried to identify the source code on GitHub but I can't actually find the 'UmbracoDatabase' class anywhere, nor can I find any documentation.
Is anyone able to shed any light? Am I being silly?
Any help is greatly appreciated!
Hi Philip,
Welcome to our.
I think you need to use the following code :
Dave
Hi Dave,
Thanks for the suggestion! :)
Unfortunately it's still throwing the same null exception. It's odd because if I remove the transaction code, calls to the DB work as expected. It's as if the connection / transaction is created at SQL run-time, for example when executing
Db.SingleOrDefault()
or
Db.Page()
It's good to know that method exists though, I had missed that earlier.
Cheers
Phil
is working on a reply...