Don't think you are, know you are

博客园 首页 新随笔 管理


不必借助监控程序(例如WIndows的性能计数器或SQL Server Profiler),SqlConnection也能获取T SQL的执行状态,结果可用于性能分析。

程序片断如下:
......
   sConn.StatisticsEnabled = true;
    
if (!string.IsNullOrEmpty(iSQL))
            {
               using (SqlCommand iCmd=new SqlCommand (iSQL,sConn ))
               {
                  iCmd .ExecuteNonQuery ();
               }           
            }
   
  IDictionaryEnumerator iEnum =sConn.RetrieveStatistics().GetEnumerator ();
......
默认情况下,SQlConnection不提供统计信息,要使用此功能需要将StatisticsEnabled 设为true. SqlConnection的 RetrieveStatistics 方法返回在调用该方法时统计数据的键值对集合,可以如代码所示获取其信息察看。

posted on 2008-05-10 22:07  炭炭  阅读(576)  评论(0编辑  收藏  举报