[英]Timeout implementation for sql stored procedure and C#
I am trying to implement timeout functionality for database stored procedure.我正在尝试为数据库存储过程实现超时功能。 This timeout value will be fetched from app.config.
此超时值将从 app.config 中获取。
I am processing thousand of records using stored procedure.我正在使用存储过程处理数千条记录。 When I call my master procedure in again calls some more store procedures inside.
当我再次调用我的主过程时,会调用更多的存储过程。 Everything has been wrapped using C# transactionScope.
一切都使用 C# transactionScope 进行了包装。 I have a list in C# which will fetch single record for processing and hits master stored procedure.
我在 C# 中有一个列表,它将获取单个记录进行处理并点击主存储过程。
I want to stop this processing as soon as timeout value matches.一旦超时值匹配,我想停止此处理。 I mean if timeout is 20 then my processing should be executed for 20 seconds and it should stop processing after 20 seconds.
我的意思是如果超时是 20 那么我的处理应该执行 20 秒,它应该在 20 秒后停止处理。
I tried using adoCommand.CommandTimeout
property but unfortunately its not stopping at all.我尝试使用
adoCommand.CommandTimeout
属性,但不幸的是它根本没有停止。
Please help.请帮忙。
A bit hard to tell what has gone wrong without looking at the code.如果不看代码,很难判断出了什么问题。
From the documentation on CommandTimeout :从CommandTimeout上的文档:
A value of 0 indicates no limit (an attempt to execute a command will wait indefinitely).
值 0 表示没有限制(尝试执行命令将无限期等待)。
The CommandTimeout property will be ignored during asynchronous method calls such as BeginExecuteReader.
在异步方法调用(例如 BeginExecuteReader)期间,将忽略 CommandTimeout 属性。
CommandTimeout has no effect when the command is executed against a context connection (a SqlConnection opened with "context connection=true" in the connection string).
当针对上下文连接(在连接字符串中使用“context connection=true”打开的 SqlConnection)执行命令时,CommandTimeout 无效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.