Multiple databases (multiple DbContexts) in one transaction using TransactionScope

c# entity-framework entity-framework-6 sql-server

Question

I have two DbContexts that connect to two separate MSSQL databases, one of which is model-first and the other is code-first. Now, whenever SaveChanges is called from any class, data is simultaneously written to both databases using the TransactionScope class. The code is shown below.

        using (TransactionScope scope = new TransactionScope())
        {
            using (Schema1Entities db1 = new Schema1Entities())
            {
                db1.SaveChanges();
            }
            using (Schema2Entities db2 = new Schema2Entities())
            {
                db2.SaveChanges();
            }
            scope.Complete();
        }

Runtime is when the issue first surfaces. It states that

An exception of type 'System.Data.Entity.Core.EntityException' occurred in EntityFramework.SqlServer.dll but was not handled in user code

Additional information: The underlying provider failed on Open.

Inner-exception message - {"The partner transaction manager has disabled its support for remote/network transactions. (Exception from HRESULT: 0x8004D025)"}

MSDTC is not being blocked by any firewalls after being enabled. need assistance right now.

1
2
6/20/2019 8:46:22 PM

Popular Answer

ZZZ_tmp
3
7/7/2016 4:04:56 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow