title: What statistics value corresponds to the ADO.net SqlCommand.CommandTimeout property?
body: <p>I am trying to understand this property, I have a function for running an sql query in ADO.net where I have set the SqlCommand.ConnectTimeout property to 500 seconds and the SqlCommand.CommandTimeout property to 1 second. Roughly the relevant portion looks like this.</p>
  <pre><code>        var conn = dbConn as SqlConnection;
          conn.ConnectTimeout = 500;
          conn.StatisticsEnabled = true;
  
          try
          {
              using (var command = new SqlCommand(query, conn))
              {
                  command.CommandTimeout = 1;
                  using (var adapter = new SqlDataAdapter(command))
                  {
                      var rowsCount = adapter.Fill(startIdx, MaxRows, new DataTable[] { dtResult });
                      var stats = conn.RetrieveStatistics();
                      long commandExecutionTimeInMs = (long)stats[&quot;ExecutionTime&quot;];
                      long commandNetworkServerTimeInMs = (long)stats[&quot;NetworkServerTime&quot;];
                      Console.Writeline(&quot;Command statistics execution time: &quot; + commandExecutionTimeInMs.ToString());
                      Console.Writeline(&quot;Command statistics network server time: &quot; + commandNetworkServerTimeInMs.ToString());
                      conn.ResetStatistics();
                      conn.StatisticsEnabled = false;
                      return rowsCount;
                  }
              }
          }
          catch (Exception ex)
          {
              var stats = conn.RetrieveStatistics();
              long commandExecutionTimeInMs = (long)stats[&quot;ExecutionTime&quot;];
              long commandNetworkServerTimeInMs = (long)stats[&quot;NetworkServerTime&quot;];
              Console.Writeline(&quot;Command statistics execution time: &quot; + commandExecutionTimeInMs.ToString());
              Console.Writeline(&quot;Command statistics network server time: &quot; + commandNetworkServerTimeInMs.ToString());
              conn.ResetStatistics();
              conn.StatisticsEnabled = false;
          } 
  </code></pre>
  <p>With this, I am expecting any execution time above 1 second to timeout and throw an exception with this message: &quot;Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.&quot;. However it is very inconsistent, my logs show me that execution time can go up to several seconds or even 10+ seconds without throwing anything sometimes. And NetworkServerTime is consistently in the 200 to 300ms range.</p>
  <p>So what is the problem here? Am I misunderstanding how CommandTimeout works? Am I looking at the wrong statistics value? I am looking to set CommandTimeout to 1, and then when my query exceeds this time I can clearly see a statistic that logs the time as 1s or 1000ms in the catch block</p>
  <p>Referring to this page nothing else seems to be relevant <a href="https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/provider-statistics-for-sql-server" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/provider-statistics-for-sql-server</a></p>