title: The configured execution strategy 'SqlAzureExecutionStrategy' does not support user initiated transactions
body: <p>I am using the latest v6 of Entity Framework along with a UnitOfWork pattern. This has been fine on a server for the past few years.</p>
  
  <p>I want to move to azure hosting and use SQLAzure, so started to migrate the app. However I have had a number of issues. </p>
  
  <p>Firstly I kept getting this error intermittently</p>
  
  <blockquote>
    <p>A transport-level error has occurred when receiving results from the
    server.</p>
  </blockquote>
  
  <p>After some Googling, it seems this is common and you need to implement your own <code>SqlAzureExecutionStrategy</code> - All seems fine. Until I then find out that it doesn't support initiated transactions!</p>
  
  <p><a href="http://ritzlgrmft.blogspot.co.uk/2014/03/working-with-sqlazureexecutionstrategy.html">I then stumbled on this blog post</a> - Which outlines the exact problems and gives example code of how to fix issues (Or so I thought).</p>
  
  <p>I have followed the post (As far as I'm aware) exactly. I have my dBconfiguration class setup and it's hitting it the SetExecutionStrategy on app start.</p>
  
  <pre><code>public class EfConfig : DbConfiguration
  {
      public EfConfig()
      {
          SetExecutionStrategy("System.Data.SqlClient", () =&gt; SuspendExecutionStrategy
                ? (IDbExecutionStrategy)new DefaultExecutionStrategy()
                : new CustomSqlAzureExecutionStrategy());
      }
  
      public static bool SuspendExecutionStrategy
      {
          get { return (bool?)CallContext.LogicalGetData("SuspendExecutionStrategy") ?? false; }
          set { CallContext.LogicalSetData("SuspendExecutionStrategy", value); }
      }
  }
  </code></pre>
  
  <p>Then I have a custom class as referenced above called 'CustomSqlAzureExecutionStrategy' which I have put below and have overridden the ShouldRetryOn method</p>
  
  <pre><code>public class CustomSqlAzureExecutionStrategy : SqlAzureExecutionStrategy
  {
      protected override bool ShouldRetryOn(Exception exception)
      {
          var shouldRetry = false;
  
          var sqlException = exception as SqlException;
          if (sqlException != null)
          {
              foreach (SqlError error in sqlException.Errors)
              {
                  if (error.Number == -2)
                  {
                      shouldRetry = true;   
                  }
  
              }
          }
          shouldRetry = shouldRetry || base.ShouldRetryOn(exception);
          return shouldRetry;
      }
  }
  </code></pre>
  
  <p>However, when I run my app I still get the same error I started with, but this time just pointing to the custom class?</p>
  
  <blockquote>
    <p>The configured execution strategy 'CustomSqlAzureExecutionStrategy'
    does not support user initiated transactions.</p>
  </blockquote>
  
  <p>Have I missed something obvious here? Or not understood something? Any help would be greatly appreciated.</p>
  
  <h2>Update</h2>
  
  <hr>
  
  <p>Typically... StackOverFlow rubber ducking. I actually read it properly and found that I need to manually set the <code>SuspendExecutionStrategy</code> in my UnitOfWork (Before BeginTransaction and after Commit).</p>
  
  <p>So I have this just before <code>.BeginTransaction()</code></p>
  
  <pre><code>EfConfig.SuspendExecutionStrategy = true;
  </code></pre>
  
  <p>And this just after <code>.Commit()</code></p>
  
  <pre><code>EfConfig.SuspendExecutionStrategy = false;
  </code></pre>
  
  <p>This allows me to run the application now, but I still (Rarely I might add) get the transient error message?</p>
  
  <blockquote>
    <p>A transport-level error has occurred when receiving results from the
    server.</p>
  </blockquote>