title: Execution strategy 'SqlServerRetryingExecutionStrategy' does not support user-initiated transactions
body: <p>I have an ASP.NET Core 5 MVC web application, working with Entity Framework Core 5.</p>
  <p>We implement web components, like Grid or Spreadsheet (we work with Telerik). When I do some changes in the component, and then try to save the changes, the component calls my <code>ApplicationDbContext.SaveChanges</code>. And then I get the following error:</p>
  <blockquote>
  <p><strong>System.InvalidOperationException</strong>: The configured execution strategy 'SqlServerRetryingExecutionStrategy' does not support user-initiated transactions. Use the execution strategy returned by 'DbContext.Database.CreateExecutionStrategy()' to execute all the operations in the transaction as a retriable unit.</p>
  </blockquote>
  <p><a href="https://i.stack.imgur.com/8F0te.png" rel="noreferrer"><img src="https://i.stack.imgur.com/8F0te.png" alt="enter image description here" /></a></p>
  <p>Here is my method where I <code>ConfigureServices</code> for the DBContext:</p>
  <pre><code>public static void AddDbContext(this IServiceCollection services, string connectionString) =&gt;
      services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
      {
          options.UseSqlServer(connectionString,
              providerOptions =&gt;
              {
                  providerOptions
                      .EnableRetryOnFailure(
                          maxRetryCount: 5, 
                          maxRetryDelay: TimeSpan.FromSeconds(30),
                          errorNumbersToAdd: null)
                      .UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery);
              });
          options.EnableSensitiveDataLogging();
          options.ConfigureWarnings(w =&gt; w.Throw(RelationalEventId.MultipleCollectionIncludeWarning));
      });
  </code></pre>
  <p>That error does not happen systematically. For sure when I try to save to DB multiple elements. But also when only one element. Does not happen when I edit or same an element one by one, in a classic form, only when it happens in multiple objects scenario (Grid or Spreadsheet)...</p>
  <p>The StackTrace would be like this:
  <a href="https://i.stack.imgur.com/1ueHL.png" rel="noreferrer"><img src="https://i.stack.imgur.com/1ueHL.png" alt="enter image description here" /></a></p>
  <p>As example, I give bellow a method allowing to submit <code>Entreprise</code> objects, from a Spreadsheet to the DB, in order to use <code>CreateExecutionStrategy</code> method:</p>
  <pre><code>public ActionResult Data_Source_Entreprises_Submit(SpreadsheetSubmitViewModel model)
  {
      var result = new SpreadsheetSubmitViewModel()
      {
          Created = new List&lt;SpreadsheetEntrepriseViewModel&gt;(),
          Updated = new List&lt;SpreadsheetEntrepriseViewModel&gt;(),
          Destroyed = new List&lt;SpreadsheetEntrepriseViewModel&gt;()
      };
  
      if ((model.Created != null || model.Updated != null || model.Destroyed != null) &amp;&amp; ModelState.IsValid)
      {
          /*             executionStrategy                                 */
          var executionStrategy = _dbContext.Database.CreateExecutionStrategy();
  
          executionStrategy.Execute(() =&gt;
              {
                  using (var transaction = _dbContext.Database.BeginTransaction())
                  {
                      try
                      {
                          ///////// Business Logic //////////////////
                          if (model.Created != null)
                          {
                              foreach (var created in model.Created)
                              {
                                  EntrepriseDTO dto = new EntrepriseDTO() { Nom = created.Nom };
                                  var createdDto = _entrepriseService.Create(dto);
                                  created.Id = createdDto.Id;
                                  result.Created.Add(created);
                              }
                          }
  
                          if (model.Updated != null)
                          {
                              foreach (var updated in model.Updated)
                              {
                                  var spec = new EntrepriseForDetailsSpecification(updated.Id);
                                  var dto = _entrepriseService.Read(spec);
                                  dto.Nom = updated.Nom;
                                  _entrepriseService.Update(dto);
                                  result.Updated.Add(updated);
                              }
                          }
  
                          if (model.Destroyed != null)
                          {
                              foreach (var destroyed in model.Destroyed)
                              {
                                  _entrepriseService.Delete(destroyed.Id);
                                  result.Destroyed.Add(destroyed);
                              }
                          }
                          ///////// END Business Logic ///////////////
  
                          transaction.Commit();
                      }
                      catch (Exception ex)
                      {
                          transaction.Rollback();
                      }
                  }
              }
          );
          /*             END executionStrategy                   */
          
          return Json(result);
      }
      else
      {
          return StatusCode(400, &quot;The models contain invalid property values.&quot;);
      }
  }
  </code></pre>
  <p>as result I had the following error:</p>
  <blockquote>
  <p>The connection does not support MultipleActiveResultSets</p>
  </blockquote>
  <p>Then I modified the connection string, including <code>MultipleActiveResultSets=True</code>, but finally obtained another error:</p>
  <blockquote>
  <p>A second operation was started on this context before a previous
  operation completed. This is usually caused by different threads
  concurrently using the same instance of DbContext. For more
  information on how to avoid threading issues with DbContext, see
  <a href="https://go.microsoft.com/fwlink/?linkid=2097913" rel="noreferrer">https://go.microsoft.com/fwlink/?linkid=2097913</a>.</p>
  </blockquote>
  <p>I don't use in that code asynchronous code, I don't know what is wrong...</p>