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
Best Answer
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
To reset the CIDs on a Windows 2012 Server use the following Powershell script: