混淆事务和MSDTC [英] confusion about transactions and msdtc

查看:185
本文介绍了混淆事务和MSDTC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有关于如何交易和MSDTC一起工作的一些基本的困惑。

I have some basic confusion about how transactions and msdtc work together.

我有一个基本的服务器/客户端的WinForms应用程序。该应用程序使用的TransactionScope封装的是SQL服务器上执行SQL命令。

I have a basic server/client winforms app. The app uses transactionscope to encapsulate several sql commands that are executed on the sql server.

该应用程序似乎正常工作时,我只启用服务器上的MSDTC网络访问。后来有一天,它停止工作,说网络访问没有启用。

The app seemed to work fine when I enabled msdtc network access on the server only. Then one day it stopped working saying network access was not enabled.

现在看来,我必须启用客户端计算机和服务器TransactionScope的工作,无论在MSDTC网络访问。

Now it seems that I have to enable msdtc network access on both the client computer and server for transactionscope to work.

请问客户端或服务器MSDTC服务做交易的工作?或者,也许它两者兼而有之?

Does the client or server msdtc service do the transaction work? Or maybe its both?

有没有人有指导MSDTC网络访问是否需要客户端和服务器或者只是服务器上?

Does anyone have guidance on whether msdtc network access is needed on both client and server or just server?

推荐答案

如果您使用的是MSDTC,那么你就需要在客户端(应用程序)和服务器(数据库),以两者运行MSDTC,并需要适当配置。

If you are using MSDTC, then you will need the client (your application) and the server (database) to both run MSDTC and also to be configured properly.

这尤其可以在与防火墙的处理是痛苦的根源。如果您无法看到故障处理与MSDTC 。它谈论的BizTalk,但它适用于MSDTC一般。 <一href="http://www.microsoft.com/DOWNLOADS/details.aspx?FamilyID=5e325025-4dcd-4658-a549-1d549ac17644&displaylang=en">DTCPING也是你的朋友。

This can be source of pain especially when dealing with firewalls. If you are having trouble see Troubleshooting Problems with MSDTC. It talks about BizTalk but it applies to MSDTC in general. DTCPING is also your friend.

现在,如果你使用的是SQL Server 2005和更高的,只访问一个数据库,使用一个数据库连接,并且没有通过应用程序域之间的交易,那么你应该不需要使用MSDTC的。在这种情况下,System.Transactions的事务管理器将管理自己的事务为您服务。如果有任何的previous情况发生那么交易将被提升到一个分布式事务(和事务管理器将MSDTC)。请参见交易管理升级了解详情。

Now if you are using SQL Server 2005 and higher, are accessing only one database, are using one database connection and are not passing Transactions between app domains then you should not require the use of MSDTC. Under those circumstances the System.Transactions transaction manager will manage your transactions for you. If any of the previous situations occurs then the transaction will be promoted to a distributed transaction (and the transaction manager will be MSDTC). See Transaction Management Escalation for more information.

一般情况下最好避免使用MSDTC,如果你不需要它。也就是说,如果你只使用一个SQL Server的2005+数据库处理,然后尝试设计您的code不使用MSDTC。除了配置的麻烦,DTC规定的性能损失,因为所有调用MSDTC外出的过程,再加上两阶段的开销提交协议(其MSDTC使用)。

In general it is best to avoid the use of MSDTC if you do not need it. i.e. if you are only dealing with a single SQL Server 2005+ database then try to design your code to not use MSDTC. Besides the configuration hassle, DTC imposes a performance penalty because all calls to MSDTC are out of process combined with the overhead of the two phase commit protocol (which MSDTC uses).

在正在发生的事情在你的具体情况而言,很难说。如果你的code并没有改变,那么也许防火墙规则有哪些变化?我也看到Windows更新改变DTC配置(安全性),这就造成了问题。

In terms of what is happening in your specific situation it is hard to say. If your code hasn't changed, then perhaps the firewall rules have changed? I have also seen Windows Updates change DTC configuration (for security) which caused a problem.

更新基于注释:

有关监控交易晋升或升级,如果你不使用任何分布式事务,我认为你可以使用一些分布式事务处理协调器性能计数器来跟踪提交的事务。如果测试您可以禁用MSDTC,看看你的code失败。另一种方式是监测在SQL Server的交易。从编程角度来说,你可以尝试处理<一href="http://msdn.microsoft.com/en-us/library/system.transactions.transactionmanager.distributedtransactionstarted.aspx">DistributedTransactionStarted事件并做一些记录(但才去生产删除code)。

For monitoring transaction promotion or escalation, if you are not using any distributed transactions I think you could use some of the Distributed Transaction Coordinator performance counters to track committed transactions. If testing you could disable MSDTC and see if your code fails. Another way would be to monitor transactions in SQL Server. From a coding perspective you could try to handle the DistributedTransactionStarted event and do some logging (but remove that code before going to production).

有关使用一个连接进入TransactionScope在MSDN页面。基本上,创建一个TransactionScope,创建一个SqlConnection,做了一些工作与SqlConnection的,关闭连接,调用scope.Complete()。

For a code example using a single connection go to the TransactionScope page at MSDN. Basically, create a TransactionScope, create a SqlConnection, do some work with the SqlConnection, close the connection, call scope.Complete().

请注意,如果您使用的是数据适配器方法,它们会自动所以连接被关闭或返回到连接池管理连接。无论哪种方式,如果被称为然后又操作的事务将被提升到一个DTC事务。请参阅<一href="http://www.softinsight.com/bnoyes/2005/09/14/SystemTransactionsAndConnectionPooling.aspx">System.Transactions和连接池了解更多详情。

Note that if you are using Data Adapter methods, they automatically manage your connection so the connection is closed or returned to the connection pool. Either way, if another operation is called then the transaction will be promoted to a DTC transaction. See System.Transactions and connection pooling for more details.

这篇关于混淆事务和MSDTC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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