我已经看到这个代码中出现了几个地方,从来没有一个解释,只是上面的一个隐秘的评论(声明和执行包括一个上下文的想法,这只是运行一个SqlCommand的标准过程):
//SqlCommand cmd = new SqlCommand(); //cmd.ExecuteReader(); //Read off the results //Cancel the command. This improves query time. cmd.Cancel ();
基本上,完成查询后,它会返回并取消它,声称有一些性能提升.我想你可能会得到一些回忆,当它去释放XmlReader,但通常它将要超出范围.
我以前从来没有打过它,但终于在我正在审查的代码中显示出来.在代码中运行它后,取消SqlCommand实际上会加快速度,还是这只是一些奇怪的程序迷信?
解决方法
根据
MSDN,这是正确的.
The Close method fills in the values
for output parameters,return values
and RecordsAffected,increasing the
time that it takes to close a
SqlDataReader that was used to process
a large or complex query. When the
return values and the number of
records affected by a query are not
significant,the time that it takes to
close the SqlDataReader can be reduced
by calling the Cancel method of the
associated SqlCommand object before
calling the Close method.
奇怪的!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。