为什么使用的TransactionScope时,我只使用LinqToSql和Ado.Net分布式事务 [英] Why is TransactionScope using a distributed transaction when I am only using LinqToSql and Ado.Net

查看:189
本文介绍了为什么使用的TransactionScope时,我只使用LinqToSql和Ado.Net分布式事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在对一台机器的问题,并显示错误消息:

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

MSDTC服务器XXX不可用。

"MSDTC on server XXX is unavailable."

在code是使用的的TransactionScope 的包裹一些LingToSql数据库code;也有一些在事务内生Ado.net。

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

由于只有一个SQL数据库(2005年)被访问,为什么被使用在所有的分布式事务?

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

(我不想知道如何启用MSDTC,为code需要与他们目前的设置工作在服务器上)

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

推荐答案

这时候您的事务使用多个数据库连接几乎总是发生。所以,让我们说你要更新两个表。您可能会更新使用一个连接的第一个表,但使用的是不同的第二个连接更新第二个表。这将导致事务被升级为MSDTC,即使使用一个TransactionScope对象

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.

我们得到了解决这个问题的方法是,当执行交易,我们用所有我们写一个单独的数据库上下文对象。这消除了升级。既然这样,我们从来没有过的MSDTC消息出现。

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.

兰迪

这篇关于为什么使用的TransactionScope时,我只使用LinqToSql和Ado.Net分布式事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆