我已经看到这个代码中出现了几个地方,从来没有一个解释,只是上面的一个隐秘的评论(声明和执行包括一个上下文的想法,这只是运行一个sqlCommand的标准过程):
@H_502_9@解决方法
//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.
奇怪的!