如果这很重要,应用程序将在与数据库不同的计算机上运行.我正在使用SQL Server 2005.
Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration
for MSDTC using the Component Services Administrative tool.
using (TransactionScope tsTransScope = new TransactionScope()) { //Do stuff here tsTransScope.Complete(); }
编辑
我根据反馈做了一些改变.现在我收到这个错误:
“Error HRESULT E_FAIL has been returned from a call to a COM component.”
“Communication with the underlying transaction manager has failed.”
解
我认为接受的答案解决了我遇到的最初问题.第二个错误似乎特定于Entity Framework.我会发布另一个问题.
以下是客户端上的属性:
Client http://www.portnine.com/data/images/Misc/client.jpg
以下是服务器上的属性:
Server http://www.portnine.com/data/images/Misc/server.jpg
以下是我们使用的屏幕截图,但“允许远程管理”选项除外:
我没有遇到你现在遇到的HRESULT E_Fail问题,但是这篇文章于XP SP2 and transactions提出了这个有趣的建议:
Another configuration setting that you
need to be aware (although I consider
it to be an uncommon scenario) is
RestrictRemoteClients registry key. If
the value of this key is set to 2
(RPC_RESTRICT_REMOTE_CLIENT_HIGH) then
MSDTC network transactions will not be
able to work properly. MSDTC supports
only RPC_RESTRICT_REMOTE_CLIENT_NONE
(0) and
RPC_RESTRICT_REMOTE_CLIENT_DEFAULT (1)
values. See
07002
for more info on
RestrictRemoteClients.
最后,虽然不是特定于您的问题,但是关于使用TransactionScope类的一个非常重要的事情是它的默认设置是使用Transaction Isolation Level of Serializable. Serializable是最严格的隔离级别,坦率地说它被选为默认值令人惊讶.如果您不需要这种级别的锁定,我强烈建议在实例化TransactionScope时将隔离级别设置为限制较少的选项(ReadCommitted):
var scopeOptions = new TransactionOptions(); scopeOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; scopeOptions.Timeout = TimeSpan.MaxValue; using (var scope = new TransactionScope(TransactionScopeOption.Required, scopeOptions)) { // your code here }