【发布时间】:2017-07-01 07:18:06
【问题描述】:
我有一个要执行的 C# 代码。
str = "SELECT u.LastName " +
",COALESCE(COUNT(DISTINCT pc.PhraseId), 0) AS CreatedByQty " +
", COALESCE(COUNT(DISTINCT pm.PhraseId), 0) AS ModifiedByQty " +
"FROM dbo.AspNetUsers u " +
"LEFT JOIN dbo.Phrase pc " +
"ON u.Id = pc.CreatedBy " +
"LEFT JOIN dbo.Phrase pm " +
"ON u.Id = pm.ModifiedBy " +
"GROUP BY u.LastName ";
threeColQuery = db.Database.SqlQuery<threeCol>(str);
threeColReport = await threeColQuery.ToListAsync();
return Ok(threeColReport);
我知道在 SQL Server 管理器中运行查询大约需要 30 秒。
在 Web API 调用中运行时,我得到以下信息:
"innerException":{"message":"An error has occurred.","exceptionMessage":"The wait operation timed
有没有一种方法可以让 WebAPI 调用运行长时间运行的查询?
【问题讨论】:
-
您可以像这样在控制器中以编程方式设置:-
HttpContext.Server.ScriptTimeout = 300; -
您可以像这样
db.Database.CommandTimeout = 60;更改DbContext的超时时间。您介意发布您的 api 代码吗? -
其实我忘了问超时是在等待api的时候在你的客户端,还是在执行查询的时候在你的api里面。
标签: c# asp.net entity-framework asp.net-web-api