title: API Calls with long DB query returning Gateway Timeout out despite extending timeouts
body: <p>I'm using Entity Framework 6 to access a SQL Server in an API application. The API server and DB server are separate. I have a known long query that takes a little more than a minute to run. I have set the CommandTimeout on my EF DbContext using the following code:</p>
  
  <pre><code>db.Database.CommandTimeout = 20 * 60;  // 20 minutes
  </code></pre>
  
  <p>Unfortunately, this does not seem to have any affect because the query still times out in less than a minute and the server returns a 504 Gateway Timeout error.</p>
  
  <p>Why does this change not have any affect on the command execution time limit?</p>
  
  <p>Is there something else I should be doing to allow this query to run longer?</p>
  
  <p>Some more details:</p>
  
  <p>I have written a desktop app that makes API calls to an API server which in turn makes queries to the db server. On the desktop application side, I have set the HttpClient property:</p>
  
  <pre><code>httpClient = new HttpClient { Timeout = new TimeSpan( 0, 20, 0 ) };
  </code></pre>
  
  <p>On the API server side, I have set the execution timeout:</p>
  
  <pre><code>&lt;system.web&gt;
      &lt;httpRuntime requestPathInvalidCharacters="" maxRequestLength="2097151" executionTimeout="30000" /&gt;
  &lt;/system.web&gt;
  </code></pre>
  
  <p>And on the API server, I've set the SQL command timeout as above.</p>
  
  <p>At some point, the response always ends after a little less than a minute despite the fact that I've set all the timeouts I can think of to 20 minutes. I assumed the 504 was caused by the db timeout, but I suppose it's just as likely that it's between the desktop app and the API server.</p>
  
  <p>Regardless, I'm running out of ideas so anything will help.</p>