title: Execute multiple queries in parallel with Dapper
body: <p>I trying to execute three similar SQL queries in parallel using Dapper and stored procedures to get three similar results after all queries are completed.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class SomeReport
  {
      private static readonly string ConnectionString = ConfigurationManager.ConnectionStrings["SomeContext"].ToString();
      public ReportStatus ReportStatus { get; set; }
      public long NetworkServerTime { get; set; }
      public string ReportLastErrorMessage { get; set; }
  
      public RowSet[] FirstRowSet { get; set; }
      public RowSet[] SecondRowSet { get; set; }
      public RowSet[] ThirdRowSet { get; set; }
  
      public Report()
      {
          NetworkServerTime = 0;
          ReportStatus = ReportStatus.NotCreated;
      }
  
  
      public async Task GetReportDataAsync(ReportParameters parameters)
      {
          DynamicParameters requestParameters = new DynamicParameters();
          requestParameters.Add("@sinceDateFilter", parameters.SinceDate?.Date, DbType.DateTime);
          requestParameters.Add("@untilDateFilter", parameters.UntilDate?.Date, DbType.DateTime);
          requestParameters.Add("@countryId", parameters.CountryId, DbType.Int32);
  
          ReportLastErrorMessage = null;
  
          Task allTasks = null;
          var stopWatch = new Stopwatch();
  
          try
          {
              var firstTask = GetRows("[dbo].[GET_Report_FirstRowSet]", requestParameters);
              var secondTask =
                  GetRows("[dbo].[GET_Report_SecondRowSet]", requestParameters);
              var thirdTask =
                  GetRows("[dbo].[GET_Report_ThirdRowSet]", requestParameters);
  
              allTasks = Task.WhenAll(firstTask, secondTask, thirdTask);
  
              FirstRowSet = await firstTask;
              SecondRowSet = await secondTask;
              ThirdRowSet = await thirdTask;
          }
          catch (Exception ex)
          {
              ReportStatus = ReportStatus.Error;
              ReportLastErrorMessage = allTasks?.Exception?.InnerExceptions.Last().Message;
          }
          finally
          {
              if (ReportStatus != ReportStatus.Error)
              {
                  ReportStatus = ReportStatus.Success;
                  NetworkServerTime = stopWatch.ElapsedMilliseconds;
              }
  
          }
          stopWatch.Reset();
      }
  
      private async Task&lt;RowSet[]&gt; GetRows(string procName, DynamicParameters parameters)
      {
          using (var conn = new SqlConnection(ConnectionString))
          {
              RowSet[] rowsSet;
  
              try
              {
                  var sqlString = string.Concat(procName, " @sinceDateFilter, @untilDateFilter, @countryId");
                  var query = await conn.QueryAsync&lt;RowSet&gt;(sqlString, parameters, commandTimeout: 500);
                  rowsSet = query.ToArray();
              }
              catch (SqlException sqlEx)
              {
                  rowsSet = new RowSet[0];
                  throw;
              }
  
              return rowsSet;
          }
      }
  }
  </code></pre>
  
  <p>But when I launch the debugger and SQL Server Profiler, I see that the queries are executed sequentially when creating the tasks corresponding to them.</p>
  
  <p>How can I make queries start running at the same time and run in parallel?</p>