用户 密码
太平洋系列网站:汽车网 | 游戏网 | 时尚女性
首 页 | 今日报价 | 新闻中心 | 数码世界 | 硬件资讯 | 软件资讯 | 下 载 | 通讯世界 | 游 戏
论 坛 | 产品大全 | 渠道商情 | 解决方案 | 招聘培训 | 产品调查 | 二 手 | 评 测 室 | 导 购
各地今日报价 北京 广州 上海 深圳 南宁 重庆 山东 南京 香港 辽宁

-
您现在的位置:软件资讯 > 开发特区 > .net技术
.NET 2.0获取数据库连接统计数据


责任编辑:linjixiong

[04-9-10 15:53] 作者: liuhm
-

  .NET 2.0中的SqlConnection多了一个StatisticsEnabled属性和ResetStatistics()、RetrieveStatistics()两个方法,用于获取SQLServer的连接统计数据。





  <%@ Import Namespace="System.Data" %>
  <%@ Import Namespace="System.Data.SqlClient" %>
  <%@ page language="C#" %>
  <script runat="server">
  void Page_Load(object sender, EventArgs e)
  {
  string connString = "Northwind的连接串";
  SqlConnection conn = new SqlConnection(connString);
  conn.StatisticsEnabled = true;
  conn.ResetStatistics();
  conn.Open();
  SqlCommand cmd = new SqlCommand("SELECT * FROM Orders", conn);
  SqlDataReader reader = cmd.ExecuteReader();
  reader.Close();
  conn.Close();

  Hashtable ht = (Hashtable)conn.RetrieveStatistics();
  foreach (string key in ht.Keys)
  {
  Label1.Text += "Key: " + key + " = " + ht[key] + "<BR />";
  }
  }
  </script>
  <html>
  <head id="Head1" runat="server">
  <title>Untitled Page</title>
  </head>
  <body>
  <form id="Form1" runat="server" autocomplete="on">
  <asp:Label ID="Label1" Runat="server" Text=""></asp:Label>
  </form>
  </body>
  </html>

  运行后的结果就是SQLServer连接统计数据结果:

  Key: NetworkServerTime = 0
  Key: BytesReceived = 156913
  Key: UnpreparedExecs = 1
  Key: SumResultSets = 1
  Key: SelectCount = 1
  Key: PreparedExecs = 0
  Key: ConnectionTime = 30
  Key: ExecutionTime = 30
  Key: Prepares = 0
  Key: BuffersSent = 1
  Key: SelectRows = 830
  Key: ServerRoundtrips = 1
  Key: CursorOpens = 0
  Key: Transactions = 0
  Key: BytesSent = 48
  Key: BuffersReceived = 20
  Key: IduRows = 0
  Key: IduCount = 0




察看评论详细内容 我要发表评论
作者笔名 简短内容 发表时间
:


ad
发给好友 我要报错 投稿给我们 加入收藏 返回顶部

-
本栏今日更新
相关文章
·好消息:腾讯QQ2004正式版已发布
·明日世界公司要与微软Office一决雌雄
·微软Virtual Server 2005下周火热发布
·SUN公司对Windows蠕虫疯狂“盖帽”
·MyIE2平滑升级Maxthon完美方案
·光盘加密大师,保护光盘中的秘密
·文件属性随心变,文件再多也不怕
·规范操作:解密U盘灵异事件
·SQL SERVER实用经验技巧集 [三]
·SQL SERVER实用经验技巧集 [二]
·SQL SERVER实用经验技巧集 [一]
·用C#快速往Excel写数据
·微软发布.NET 1.0 SP3和.NET 1.1 SP1
·微软.NET Framework 1.1 SP1发布
·在视图状态中保存自定义的对象
·ASP.NET中不定级动态菜单的实现
文章搜索
高级搜索
本栏今日焦点
IT培训十大热门文章
-