问题
I received the following error when I tried to run a C# WinForms application on a Windows Server 2003 Standard Edition SP1 machine that was connecting to a SQL server 2000, converting the data in the WinForms app and inserting the converted into a SQL server 2005 application. I am connecting to each database using SSPI.
The code was contained within a TransactionScope block:
System.TimeSpan TransactionTimeOut = new TimeSpan(0, 40, 0);
using(TransactionScope Scope = new TransactionScope(TransactionScopeOption.RequiresNew, TransactionTimeOut))
{
try
{
//meat of transaction...
}
catch(Exception ex)
{
throw ex;
}
Scope.Complete();
}
Error Messages:
Exception: The transaction has already been implicitly or explicitly committed or aborted.
Inner Exception: The transaction has already been implicitly or explicitly committed or aborted (Exception from HRESULT: 0x8004D00E)
Any one know what might be causing this issue?
回答1:
Check that the DTC is started on the machine where your code is running. Since you are using 2 connections in the transactionscope, the transaction will be promoted to a DTC based transaction.
Also, check that the security is configured correctly (check this by allowing anonymous participation in the DTC transaction), and that your firewall is allowing the DTC through it.
Check out this forum FAQ: Distributed Transaction Coordinator(MSDTC) and Transaction FAQ
[Related to this SO question: Distributed Transaction Coordinator]
回答2:
How long is this process taking? If you hit your timeout (unlikely with a 40 minute timeout, but still possible), you could receive that error message.
Otherwise, are you receiving the exception? What is occurring before the exception is thrown?
来源:https://stackoverflow.com/questions/784047/hresult-0x8004d00e-using-transactionscope-c-sharp