开发者

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

开发者 https://www.devze.com 2022-12-28 03:08 出处:网络
We are having problems on one machine, with the error message: \"MSDTC on server XXX is unavailable.\"

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开发者_如何学C on the server with their current setup)


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

0

精彩评论

暂无评论...
验证码 换一张
取 消