MVC 3 : The MSDTC transaction manager was unable to pull the transaction from the source

痴心易碎 提交于 2019-12-30 08:01:52

问题


I am using MVC 3 with Entities, now I have used the below line of codes from my controller

        using (var scope = new TransactionScope())
        {
            _myRepository.DeleteFM1(id);
            _myRepository.DeleteFM2(id, name);
            scope.Complete();
        }

and inside my DeleteFM2 method which happens to be my method defined in the Entity class is as follows :

    public void DeleteFM2(int id, string name)
    {
        var data= _repositoryMD.Fetch().Where(mColl => mColl.Col1 == id);

        if (data!= null)
        {
                //insert here is giving some error MSDTC error !
                // here I prepare a message using the '**data**'
                _repositoryHistory.Insert(name, message, "FM2", "Delete", dateTime);


                _repositoryMD.Attach(data);
                _repositoryMD.Delete(data);
                _repositoryMD.SaveChanges();
            }
        }
    }

and I have a seperate class where I have defined the Insert method as

   public bool Insert(string realName, string logMessage, string tableName, string changeType, DateTime dateTime)
    {
        var history = new History
        {
            ModifiedBy = realName,
            ChangeType = changeType,
            DateModified = dateTime,
            LogMessage = logMessage,
            TableName = tableName
        };

        _repositoryHistory.Add(history);
        _repositoryHistory.SaveChanges();

        return true;
    }

After inserting this line of code in the above method DeleteFM2

      _repositoryHistory.Insert(name, message, "FM2", "Delete", dateTime);

I am getting this error, without this line my code works just fine, I have used this line in all of my other methods too even where I there I had used Transaction Scope, but I still dont seem to understand the problem here. Please help. Thanks

The underlying provider failed on Open.

System.Transactions.TransactionManagerCommunicationException: Communication with the underlying transaction manager has failed. ---> System.Runtime.InteropServices.COMException: The MSDTC transaction manager was unable to pull the transaction from the source transaction manager due to communication problems. Possible causes are: a firewall is present and it doesn't have an exception for the MSDTC process, the two machines cannot find each other by their NetBIOS names, or the support for network transactions is not enabled for one of the two transaction managers. (Exception from HRESULT: 0x8004D02B) at System.Transactions.Oletx.IDtcProxyShimFactory.ReceiveTransaction(UInt32 propgationTokenSize, Byte[] propgationToken, IntPtr managedIdentifier, Guid& transactionIdentifier, OletxTransactionIsolationLevel& isolationLevel, ITransactionShim& transactionShim) at System.Transactions.TransactionInterop.GetOletxTransactionFromTransmitterPropigationToken(Byte[] propagationToken) --- End of inner exception stack trace --- at System.Transactions.TransactionInterop.GetOletxTransactionFromTransmitterPropigationToken(Byte[] propagationToken) at System.Transactions.TransactionStatePSPEOperation.PSPEPromote(InternalTransaction tx) at System.Transactions.TransactionStateDelegatedBase.EnterState(InternalTransaction tx) at System.Transactions.EnlistableStates.Promote(InternalTransaction tx) at System.Transactions.Transaction.Promote() at System.Transactions.TransactionInterop.ConvertToOletxTransaction(Transaction transaction) at System.Transactions.TransactionInterop.GetExportCookie(Transaction transaction, Byte[] whereabouts) at System.Data.SqlClient.SqlInternalConnection.GetTransactionCookie(Transaction transaction, Byte[] whereAbouts) at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx) at System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx) at System.Data.SqlClient.SqlInternalConnectionTds.Activate(Transaction transaction) at System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction) at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open() at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)

My FireWall settings


回答1:


The error implies that MSDTC is either not running on the database server that contains the database which _repositoryHistory targets; or that there is a network issue preventing propagation of the transaction to that machine.

Check that MSDTC is installed and running on the database server.

Check whether Windows Firewall is running on the target server; if it is, check the firewall exclusions for MSDTC. This link helps with that: http://technet.microsoft.com/en-us/library/cc725913(v=ws.10).aspx




回答2:


I also encountered this error even though the config, firewalls and netbios/dns were set up correctly. The two servers in my setup were clones of one another, so MSDTC on each server had the same CID value, which makes them not able to interoperate.

Here are some other things to think about when troubleshooting MSDTC http://msdn.microsoft.com/en-us/library/aa561924.aspx My situation is described under Ensure that MSDTC is assigned a unique CID value

The MSDTC feature of the Windows operating system requires unique CID values to ensure that MSDTC functionality between computers works correctly. Disk duplicate images of Windows installations must have unique CID values or MSDTC functionality may be impaired. This can occur when using virtual hard disks to deploy an operating system to a virtual machine.

To determine if MSDTC CID values for computers that are running the Windows operating system are unique, check the values for the entries under the HKEY_CLASSES_ROOT\CID registry key on both computers. If these values are not unique for each computer then follow the steps in the section Consider reinstalling the Distributed Transaction Coordinator service if other troubleshooting steps are not successful to reinstall MSDTC on one of the computers, which will then generate unique MSDTC CID values for that computer and accommodate proper MSDTC operations.

To reset the CIDs on a Windows 2012 Server use the following Powershell script:

#View: CIDs (These must be different on all systems)
ls Microsoft.PowerShell.Core\Registry::HKEY_CLASSES_ROOT\CID | select Name


#reinstall MSDTC to regenerate CIDs. 
msdtc -uninstall
sleep 5
msdtc -install
sleep 5
Set-Service msdtc -startuptype "auto"
#then reboot for changes to take effect



回答3:


Use DTCPing to troubleshoot DTC related errors. This has been the go to tool for me for many years to troubleshoot distributed transaction writes in our system.




回答4:


After trying everything else here, I had to add the DTC Service (MSDTC.EXE) to my firewall.
The default firewall settings for the "Distributed Transaction Coordinator" was using "%SystemRoot%\system32\svchost.exe".
Adding a new rule with MSDTC.EXE fixed the issues.




回答5:


I've had the same problem now for a couple weeks. We have two web servers (Win 2012) and one DB server (Win 2008). Turns out that enabling the "no authentication" option for security solved our problem.

CIDs : all different on each server MSDTC Network Access : Enabled MSDTC Remote Access : Enabled MSDTC Remote Admin : Disabled MSDTC No Authentication : Enabled

Now it works properly in the server farm.




回答6:


Try to Recycle the application pool of the given MVC web application. I have experienced this issue, and found this to help immediately.




回答7:


I had the same issue and in my case the issue was resolved when enabled No Authentication in MSDTC settings.



来源:https://stackoverflow.com/questions/10346367/mvc-3-the-msdtc-transaction-manager-was-unable-to-pull-the-transaction-from-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!