I am having an issue with using TransactionScope that has has two Entity Framework ObjectContexts initialized in it, one for database X and one for database Y on the same server.
The first context "cersCtx" creates a new "Contact" object. The second context "coreCtx" attempts to find an Account.
On the call on the second context to find the account
account = coreCtx.Accounts.SingleOrDefault(p => p.Email == email && !p.Voided);
I get the following error:
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)
The odd thing is, when I go into MSDTC, I am seeing there is transactions that are committed but most often they are Aborting.
Anyone have any ideas on how I can resolve this issue?
Here is an abbreivated sample of code that produces this issue.
public void CreateContact(string email)
{
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }))
{
using (CERSEntities cersCtx = new CERSEntities())
{
Contact contact = new Contact();
contact.Email = email;
cersCtx.Contacts.AddObject(contact);
cersCtx.SaveChanges();
}
CoreModel.Account account = null;
using (CoreModel.CoreEntities coreCtx = new CoreModel.CoreEntities())
{
account = coreCtx.Accounts.SingleOrDefault(p => p.Email == email && !p.Voided);
}
scope.Complete();
}
}
User contributions licensed under CC BY-SA 3.0