I have used SqlAzureExecutionStrategy in EF and for transient fault handling in the Azure SQL database. When I used transaction, it was throwing error "The configured execution strategy 'SqlAzureExecutionStrategy' does not support user-initiated transactions.". So, I added a property SuspendExecutionStrategy as given below which when set to true resolves the user-initiated transactions. My question is if one user sets SuspendExecutionStrategy to true to run a transaction, will another user get a transient fault error? I found in this post that callcontext is thread-specific. EF 6 suspend Execution Strategy and overlapping executions - "does not support user initiated transactions" exception Is this a good approach? Or should I go for manually calling strategy like mentioned here How to use SqlAzureExecutionStrategy and "Nolock"
public class MyConfiguration : DbConfiguration
{
public MyConfiguration()
{
this.SetExecutionStrategy("System.Data.SqlClient", () => SuspendExecutionStrategy
? (IDbExecutionStrategy)new DefaultExecutionStrategy()
: new SqlAzureExecutionStrategy());
}
public static bool SuspendExecutionStrategy
{
get
{
return (bool?)CallContext.LogicalGetData("SuspendExecutionStrategy") ?? false;
}
set
{
CallContext.LogicalSetData("SuspendExecutionStrategy", value);
}
}
}
user code:
try
{
using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.RequiresNew, System.TimeSpan.FromSeconds(6000)))
{
DataContextConfiguration.SuspendExecutionStrategy = true;
//database operations
}
}
finally
{
DataContextConfiguration.SuspendExecutionStrategy = false;
}