How should you close petapoco db context connection?
Hi,
I am using this to create a db connection called on the saving event:
var db = ApplicationContext.Current.DatabaseContext.Database;
If I add db.CloseSharedConnection(); after the logic an error occurs:
the slqtransation has completed, it is no longer usable. This happens if I add a using block too.
If I remove db.CloseSharedConnection() it works.
Question is how are you suppose to close this DatabaseContext, or do you not actually need to?
How should you close petapoco db context connection?
Hi,
I am using this to create a db connection called on the saving event:
var db = ApplicationContext.Current.DatabaseContext.Database;
If I add db.CloseSharedConnection(); after the logic an error occurs: the slqtransation has completed, it is no longer usable. This happens if I add a using block too.
If I remove db.CloseSharedConnection() it works.
Question is how are you suppose to close this DatabaseContext, or do you not actually need to?
Thank!
Hi Damon,
You don't need to close it, and really shouldn't.
This is Umbraco's own database context and, as you discovered, Umbraco won't work without it. Umbraco is responsible for opening/closing as necessary.
is working on a reply...