Why is TransactionScope using a distributed transaction when I am only using LinqToSql and Ado.Net

限于喜欢 提交于 2020-01-30 06:01:39

问题


We are having problems on one machine, with the error message:

"MSDTC on server XXX is unavailable."

The code is using a TransactionScope to wrap some LingToSql database code; there is also some raw Ado.net inside of the transaction.

As only a single sql database (2005) is being accessed, why is a distributed transaction being used at all?

(I don’t wish to know how to enable MSDTC, as the code needs to work on the server with their current setup)


回答1:


This almost always happens when your transaction uses more than one database connection. So, let's say you are updating two tables. You might update the first table using one connection but update the second table using a different second connection. This will cause the transaction to be escalated to MSDTC, even using a TransactionScope object.

The way we got around this is when performing transactions, we use a single database context object for all our writes. This eliminated the escalation. Since doing this, we've never had the MSDTC message appear.

Randy



来源:https://stackoverflow.com/questions/2721620/why-is-transactionscope-using-a-distributed-transaction-when-i-am-only-using-lin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!