不必借助监控程序(例如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 方法返回在调用该方法时统计数据的键值对集合,可以如代码所示获取其信息察看。

相关文章:

  • 2021-07-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-18
  • 2021-12-04
  • 2021-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-18
  • 2021-05-29
  • 2022-12-23
  • 2021-10-21
  • 2022-12-23
  • 2021-09-16
相关资源
相似解决方案