c# - 如何避免在执行 C# Azure Function 期间出现 SqlClient 超时错误?

标签 c# azure stored-procedures azure-functions azure-sql-server

我用 C# 创建了一个函数应用程序时间触发器。 在逻辑内部,我调用并执行在 SQL Server 中创建的存储过程。

存储过程的执行时间超过 8 分钟,并且我在 Azure 函数应用日志中收到以下错误:

2018-04-02T11:03:46.409 [Error] Exception while executing function: Functions.AbarIomWeeklyUsage. mscorlib: Exception has been thrown by the target of an invocation. .Net SqlClient Data Provider: Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The wait operation timed out. 2018-04-02T11:03:46.425 [Error] Function completed (Failure, Id=1b85e7ef-ea52-4fd3-ab79-f27d188c5cac, Duration=30323ms)

到目前为止我尝试了两件事: 1.利用应用程序连接字符串中的连接超时 2.在host.json

中添加超时

但它仍然给我同样的错误 30 秒超时。

有人有同样的经历或有解决方案吗?

最佳答案

您肯定超过了默认命令超时(默认为 30 秒)。如果不设置SqlCommand.CommandTimeout你会得到一个SqlException。在代码中将命令的 CommandTimeout(没有对此进行配置)设置为 10 分钟(600 秒),与函数超时相同。

关于c# - 如何避免在执行 C# Azure Function 期间出现 SqlClient 超时错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49610670/

相关文章:

c# - 委托(delegate)不变性和赋值运算符

C# 对象到字符串并返回

python - Microsoft Azure情感API返回[ "statusCode": 404, "message": "Resource not found"]错误

sql - SSIS 在更新期间挂起,有 300 万行

oracle - 从Grails调用Oracle软件包

c# - API 不可知 Vector3、Matrix 等?

c# - Xamarin MonoAndroid Azure移动服务InsertAsync

c# - 在 Azure 认知搜索中使用正则表达式(lucene 语法)搜索单个字符

Azure 存储队列 - 检索隐藏消息

mysql - 如何在MySql存储过程中同时使用Count和Like子句?