Transaction for two different entities in Entity Framework 4

1

I have two different entities of different databases. In my process I want to manipulate both databases, and the whole process must be in transaction. I have tried with TransactionScope. It works fine for single entity.

var entity1 = clsProject.GetEntity1();
var entity2 = clsProject.GetEntity2();
System.Transactions.TransactionScope tranScope = new System.Transactions.TransactionScope();
entity1.Connection.Open();
entity2.Connection.Open();

//Do operations
entity1.SaveChanges(false);
entity2.SaveChanges(false);
tranScope.Complete();
entity1.AcceptAllChanges();
entity2.AcceptAllChanges();

But, it raises an error at this line:entity2.Connection.Open(); Error Message: The underlying provider failed on Open. Inner Exception: The partner transaction manager has disabled its support for remote/network transactions. (Exception from HRESULT: 0x8004D025)

Please give your ideas for this.

Thanks in Advance,

Naresh Goradara

sql-server-2008
c#-4.0
entity-framework-4
transactionscope
asked on Stack Overflow Jul 26, 2011 by Naresh Goradara

2 Answers

3

If your second database is on another server you need to turn on Distributed Transaction Coordinator on both servers, and TransactionScope will work.

answered on Stack Overflow Jul 26, 2011 by Eugene S.
1

As stated earlier, you'll need to enable the Distributed Transaction Coordinator, but you'll also need to configure it to allow incoming and/or outgoing connections.

In addition: for testing purposes, you can set it to not require any authentication.

All of these settings are available on the "Security" tab of the "Distributed Transaction Coordinator" in the "Component Services" MMC.

All of this can be found on the link provided by "Eugene S.": Distributed Transaction Coordinator

One other thing of note: Microsoft has a DTC testing tool known as DTCPing. You can extract this tool to both servers that are to be involved in the transaction, run the programs on each server simultaneously and ether the "transaction partners" name (which is just the name of the other computer). Hit the run button on each server and the tool will run some tests for you - it has some fairly good error reporting too.

answered on Stack Overflow Jul 26, 2011 by NTDLS

User contributions licensed under CC BY-SA 3.0