Copied to clipboard

Flag this post as spam?

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


  • Damon 217 posts 287 karma points
    Jul 04, 2018 @ 12:04
    Damon
    0

    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!

  • Jason Elkin 38 posts 351 karma points MVP 2x c-trib
    Jul 04, 2018 @ 22:30
    Jason Elkin
    1

    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.

Please Sign in or register to post replies

Write your reply to:

Draft