|
Debugging #2: Page
Tracing/Timing by Charles Carroll
This page demonstrates how a page
can use tracing to time tasks to the millisecond and place debug data into pages. The nicest part about
the tracing presented here is that it can be left in pages and switched on or
off as a group with one page directive.
filename=\experiments\tracewow\sqlclientdropdown.aspx
<%@ trace="true"%>
<%@ Import Namespace="System.Data.sqlclient" %>
<%@ Import Namespace="System.Configuration.ConfigurationSettings" %>
<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
trace.tracemode=TraceMode.SortByTime
dim conn,conn2,conn3 as sqlconnection
TRY
Dim strConn as string = AppSettings("LearnaspSamples")
trace.warn("dataread", "connection string: " & strConn)
Dim strSQL as string ="select distinct city from publishers"
trace.write("city read","start")
Conn=New SQLConnection(strConn)
Dim Cmd as New SQLCommand(strSQL,Conn)
Conn.Open()
cy.DataSource = Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)
cy.DataBind()
trace.write("city read","finished")
trace.write("state read","start")
strSQL="select distinct state from publishers"
Conn2=New SQLConnection(strConn)
Dim Cmd2 as New SQLCommand(strSQL,Conn2)
Conn2.Open()
st.DataSource = Cmd2.ExecuteReader(system.data.CommandBehavior.CloseConnection)
st.DataBind()
trace.write("state read","finished")
trace.write("zip read","start")
strSQL="select distinct zip from publishers"
conn3=New SQLConnection(strConn)
Dim Cmd3 as New SQLCommand(strSQL,Conn3)
Conn3.Open()
zp.DataSource = Cmd3.ExecuteReader(system.data.CommandBehavior.CloseConnection)
zp.DataBind()
trace.write("zip","finished")
CATCH exc1 as exception
litExc.text=exc1.tostring()
FINALLY
If not(conn is Nothing)
IF Conn.State=System.Data.Connectionstate.Open THEN Conn.Close()
End If
If not(conn2 is Nothing)
IF Conn2.State=System.Data.Connectionstate.Open THEN Conn2.Close()
End If
If not(conn3 is Nothing)
IF Conn3.State=System.Data.Connectionstate.Open THEN Conn3.Close()
End If
END TRY
End Sub
</script>
<html><head>
<title>Dropdowns</title>
</head>
<body bgcolor="#FFFFFF">
<asp:literal id="litExc" runat="server" />
<form runat="server">
<asp:Table runat="server" GridLines="both" BorderWidth="1px">
<asp:TableRow>
<asp:TableCell>City</asp:TableCell>
<asp:TableCell><ASP:DropDownList id="cy" datatextfield="city" runat="server"/></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>State</asp:TableCell>
<asp:TableCell><ASP:DropDownList id="st" datatextfield="state" runat="server"/></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Zip</asp:TableCell>
<asp:TableCell><ASP:DropDownList id="zp" datatextfield="zip" runat="server"/></asp:TableCell>
</asp:TableRow>
</asp:table>
</form>
</body></html>
 |  |  |
 |
There are many worthy charities!!. But perhaps help starving children in Africa or South America AND help Charles too.
a $5 tip buys him lunch at McDonalds,
a $20 tip buys his kid Hitoshi a new computer game,
a $39 tip buys his daughter Michiko a few nice outfits.
See our donor list.
|  |
 |  |  |
|
|
|
|