We are using RDS (Amazon Relational Database Service) for our db . we have some sp s which called in a transactionScope. we ahve Customized ExecutionStrategy for our DBConfig like this
public class MpDbConfiguration : DbConfiguration
{
public MpDbConfiguration()
{
//SetExecutionStrategy(
// "System.Data.SqlClient", () => new MpExecutionStrategy(10, TimeSpan.FromMilliseconds(100)));
SetExecutionStrategy("System.Data.SqlClient", () => SuspendExecutionStrategy
? (IDbExecutionStrategy)new DefaultExecutionStrategy()
: new MpExecutionStrategy(10, TimeSpan.FromMilliseconds(100)));
}
//.....
}
SuspendExecutionStrategy is set to True when we have user transaction (related article made me use this defaultStrategy : https://docs.microsoft.com/en-us/ef/ef6/fundamentals/connection-resiliency/retry-logic)
Issue : I have this issue when I run the transactions like this
using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }))
{
if (entity != null && !string.IsNullOrEmpty(entity.EmailAddress))
{
ObjectFactory.GetInstance<IBankingService>().UnRegister(RequestContext.Current, entity);
}
Data.Configuration.MpDbConfiguration.SuspendExecutionStrategy = true;
Context.Current.Database.ExecuteSqlCommand("DeleteAccountByEmailAddress @usertodelete",
new SqlParameter("usertodelete", emailAddress));
scope.Complete();
Data.Configuration.MpDbConfiguration.SuspendExecutionStrategy = false;
}
//....
This SP is a very big transaction but uses JUST one database . The error I get is to Enable DTC. my question is WHY I NEED DTC
The underlying provider failed on 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.
Actually these terms are pretty new for me, but based on a search I found out DTC is just used when we have Distributed Transactions. In out case, we dont have it .
TransactionScope
? DoesUnRegister
talk to a database? Also, if you're only performing one SQL operation - why useTransactionScope
? - perhaps just use a regular transaction - or, since you seem to be using a stored procedure - just make the SP work in an atomic way, perhaps using a transaction internally (and no transaction at the caller)