I'm using TransactionScope
to make a method that contains multiple sql statements transactional. Now i need to call a second method that also uses the same connection and i receive following exception at connection.Open()
:
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.
So this is the pseudo-code:
public static void Method1()
{
using (TransactionScope scope = new TransactionScope())
{
bool success = true; // will be set to false in an omitted catch
using (var connection = new SqlConnection(ConnectionString1))
{
// ...
if(somethingHappened)
Method2();
}
if(success)
scope.Complete();
}
}
public static void Method2()
{
using (var connection = new SqlConnection(ConnectionString1))
{
connection.Open(); // BOOOM!
// ...
}
}
How to avoid this exception without repeating the code from Method2
in Method1
?