SqlCommand.ExecuteScalar取消 [英] SqlCommand.ExecuteScalar Cancel

查看:244
本文介绍了SqlCommand.ExecuteScalar取消的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法运行 SqlCommand.ExecuteScalar()异步,然后取消它(在服务器端也一样),而它正在执行?

Is there any way to run SqlCommand.ExecuteScalar() asynchronously and then cancel it (on the server side as well) whilst it's being executed?

推荐答案

.NET框架4.5有一个ExecuteScalarAsync()方法。
在这里看到:<一href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalarasync(v=vs.110).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalarasync(v=vs.110).aspx

.NET Framework 4.5 has a ExecuteScalarAsync() method.
See here: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalarasync(v=vs.110).aspx

ExecuteScalarAsync()也具有与可以在使用前的命令超时期满放弃的操作的参数的CancellationToken过载

ExecuteScalarAsync() also has an overload with a CancellationToken parameter that can be used to abandon the operation before the command timeout elapses.

这篇关于SqlCommand.ExecuteScalar取消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆