首页 > 解决方案 > 在 .NET Core 2.2 中从 UI 执行存储过程时出现 TimeoutException

问题描述

我需要在等待操作之后执行存储过程。我目前正在使用 EF 执行存储过程_dbContext.Database.ExecuteSqlCommand

我在 Web API 解决方案中编写了该功能。当我从 POSTMAN 调用 Web API 时,它成功执行了该过程,没有任何问题。

但是当我尝试从我的 UI 界面执行该过程时,它会引发“超时异常”。

public async void ProcessEmployeeDetailsAsync(XmlDocument xmlContent)
{
    // Some Business logic

    if (_dbContext.Entry(EmployeeBatch).State == EntityState.Modified)
    {
        var recordCount = await _dbContext.SaveChangesAsync();

        if (recordCount > 0)
        {
             SqlParameter EmpBatchId = new SqlParameter("@IPV_EmployeeBatchId", batchId);
             _dbContext.Database.ExecuteSqlCommand(
                                    "exec uspEmployeeBatchValidation_BatchId @IPV_BatchId",
                                    EmpBatchId);  // TimeOutException occuring
         }
    }
}

启动.cs

services.AddDbContextPool<EmployeeContext>((serviceProvider, optionBuilder) =>
            {
                optionBuilder
                    .UseLazyLoadingProxies()
                    .UseSqlServer(_Configuration.GetConnectionString("EmployeeContext"));
            });

谁能帮我在我失踪的地方?因为我是异步编程的新手。

标签: c#sql-serverentity-frameworkasp.net-core.net-core

解决方案


推荐阅读