Recommended practice for stopping transactions escalating to distributed when using transactionscope

后端 未结 1 574
星月不相逢
星月不相逢 2021-02-14 08:57

Using the TransactionScope object to set up an implicit transaction that doesn\'t need to be passed across function calls is great! However, if a connection is opened whilst ano

相关标签:
1条回答
  • 2021-02-14 09:19

    One of the primary reasons for transaction escalation is when you have multiple (different) connections involved in a transaction. This almost always escalates to a distributed transaction. And it is indeed a pain.

    This is why we make sure that all our transactions use a single connection object. There are several ways to do this. For the most part, we use the thread static object to store a connection object, and our classes that do the database persistance work, use the thread static connection object (which is shared of course). This prevents multiple connections objects from being used and has eliminated transaction escalation. You could also achieve this by simply passing a connection object from method to method, but this isn't as clean, IMO.

    0 讨论(0)
提交回复
热议问题