我正在使用 PowerShell 脚本和 .NET Core 应用程序将大约 50k 行插入到数据库中(应用程序 1 (PowerShell) 正在将数据发送到应用程序 2 (.NET Core),它正在插入数据)。
我正在使用 Entity Framework 并在 App 2 中实现了一种机制以加快插入速度,大致如下:Fastest Way of Inserting in Entity Framework
发生的事情是插入需要一点时间,但是所有数据都正确插入数据库后一切顺利。查询运行大约 4 分钟。
但是,App 1 返回一个通用的“HTTP 错误 502.3 - 错误网关”。甚至在所有数据都被插入数据库之前就返回了这个响应。因此,App 2 只是发回一个错误,但数据库操作继续进行,就好像什么也没发生一样。
所以问题是,数据库插入工作正常,但我无法在 App 1 中知道这一点,因为每次我得到的都是一般错误。
我尝试增加 IIS 超时、两个应用程序中的 session 超时、读取 IIS 日志和 NET Core 生成的应用程序日志。没有成功。
如何让 App 2 等到查询完成才能获得正确的响应?
.NET Core 版本为 1.0.0-preview2-003121
Powershell 请求:
$post = Invoke-WebRequest -Uri ([string]$ApiUrl+$moduleApi) -Method Post -ContentType "application/json; charset=utf-8" -Body $json -Headers @{'ClientID' = "$clientID"; "Authorization"="Bearer $encryption"} -ErrorVariable errorMsg -UseBasicParsing -TimeoutSec 600
最佳答案
将 requestTimeout
增加到超过四分钟。
ASP.NET Core Module configuration reference
requestTimeout
Optional timespan attribute.
Specifies the duration for which the ASP.NET Core Module will wait for a response from the process listening on
%ASPNETCORE_PORT%
.The default value is "00:02:00".
关于c# - 插入数据库时出现 .NET Core 错误 502.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42718709/