I am using Entity Framework 5 and need to make multiple stored procedure calls in a single transaction. They are all inserts where each depends on an output of the previous one and I want to be able to roll everything back in case one fails. Each call uses the same Entities object. The first call executes successfully, but the next one always fails with the following error:
"The underlying provider failed on Open."
Inner exception: "Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool."
Inner Inner exception: "The transaction manager has disabled its support for remote/network transactions. (Exception from HRESULT: 0x8004D024)"
Is there a way to do this without going down the DTC road?
Code:
ObjectParameter outputParam1 = new ObjectParameter("newEntity1", 0);
ObjectParameter outputParam2 = new ObjectParameter("newEntity2", 0);
using (var scope = new TransactionScope())
{
try
{
using(var context = new DatabaseContext())
{
context.f_createEntity1(outputParam1);
}
using(var context = new DatabaseContext())
{
context.f_createEntity2(ouputParam2, outputParam1.Value);
}
... other calls ...
scope.Complete();
}
catch (Exception ex)
{
... handle error ...
}
}