asp.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
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器