当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > ASP.NET 2.0里轻松获取数据库连接统计数据

ASP.NET
ASP.NET上传图片时 产生预览
动态改变asp.net网页的标题
一个ASP.NET中使用的MessageBox类
ASP.NET设计网络硬盘之两重要类
ASP.NET与MySQL数据库简明图示入门教程
ASP.NET中为DataGrid添加合计字段
利用ASP.NET的内置功能抵御Web攻击
ASP.NET+Web服务实现软件共享
ASP.NET设计网络硬盘之文件夹实现
在ASP.NET中使用SQL的IN操作
datagrid与DataSet结合使用中出现的索引问题
asp.net开发web项目-vss集成环境配置
ASPX保存远程图片到本地的两种方法的函数
ASP.NET设计网络硬盘之删除文件夹
开发ASP.NET下的MP3小偷程序
对“学号”、“身份证”的数字分析
Asp.net url分页的用户控件
ASP.NET 2.0中DataTable小兵变大将
将dataset以xml形式发给客户端下载
ASP.NET实现自适应图片大小的弹窗 窗口可任意编辑

ASP.NET 2.0里轻松获取数据库连接统计数据


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 75 ::
收藏到网摘: n/a

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

<%@ImportNamespace="System.Data"%>
<%@ImportNamespace="System.Data.SqlClient"%>
<%@pagelanguage="C#"%>
<scriptrunat="server">
voidPage_Load(objectsender,EventArgse)
{
stringconnString="Northwind的连接串";
SqlConnectionconn=newSqlConnection(connString);
conn.StatisticsEnabled=true;
conn.ResetStatistics();
conn.Open();
SqlCommandcmd=newSqlCommand("SELECT*FROMOrders",conn);
SqlDataReaderreader=cmd.ExecuteReader();
reader.Close();
conn.Close();

Hashtableht=(Hashtable)conn.RetrieveStatistics();
foreach(stringkeyinht.Keys)
{
Label1.Text+="Key:"+key+"="+ht[key]+"<BR/>";
}
}
</script>
<html>
<headid="Head1"runat="server">
<title>UntitledPage</title>
</head>
<body>
<formid="Form1"runat="server"autocomplete="on">
<asp:LabelID="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