1

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:

db.Database.CommandTimeout = 20 * 60;  // 20 minutes

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.

Why does this change not have any affect on the command execution time limit?

Is there something else I should be doing to allow this query to run longer?

Some more details:

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:

httpClient = new HttpClient { Timeout = new TimeSpan( 0, 20, 0 ) };

On the API server side, I have set the execution timeout:

<system.web>
    <httpRuntime requestPathInvalidCharacters="" maxRequestLength="2097151" executionTimeout="30000" />
</system.web>

And on the API server, I've set the SQL command timeout as above.

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.

Regardless, I'm running out of ideas so anything will help.

4

1 回答 1

2

原来还有另一个我没有考虑过的超时设置。因为我使用 Elastic Beanstalk 在 Amazon Web Services 上托管 API 和数据库服务器,所以在我的桌面应用程序和 API 服务器之间有一个负载均衡器。默认超时为 60 秒。这是增加负载均衡器超时设置的链接:

http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/config-idle-timeout.html

于 2016-03-09T21:35:55.087 回答