Professional Documents
Culture Documents
Errors
• Types
• Syntax Errors
• Semantic Errors
• VS.NET automatically gives us syntax
notifications while we edit the code and marks
out the syntax errors. This support extends not
only to the programming language but also XML.
• VS.NET also has TaskList that displays a list of
errors.
What is Debugging?
• Debugging is the process of tracking and removing
logical or runtime errors in the program.
• Debugging is achieved through Tracing.
• Tracing is the process of collecting information about a
program’s execution.
<system.web>
<trace enabled="true" pageOutput="true"/>
</system.web>
Trace information listing
• As we see in the output, trace lists
• Request details
• Trace information: Four column output: Category,
Message, Time from the first trace item, Duration of
this trace item.
• Control tree: the entire collection of controls in the
ASP.NET page displayed hierarchically.
• Collection information: any defined members of the
following collections will also be displayed:
• Session state
• Cookies
• Headers
• Form
• Querystring
• Server variables
System.Diagnostics
• Debug class and Trace class
• VS.NET provide two basic configurations for a project :
• Debug (the default)
• Release
• When a program is compiled using the Debug
configuration both the TRACE and DEBUG conditional
compilation symbols are defined
• In the Release configuration only trace information is
compiled.
• These modes are configurable via the property pages of
the VS.NETsolution.
• Examples:
• Debug.Assert(value<0, "Invalid
value","negative value employed in
debug mode");
Trace.Writeline(value,"Program trace,
value of value");
Starting a VS.NET Debugger
• By default when .aspx files are compiled the
debugging symbols are automatically inserted
into the compiled page.
• This is because the in web.config file by default
the debug is set to true for compilation.
<system.web>
...
<compilation debug="true"/>
...
</system.web>
• Because this affects performance, set this value
to true only during development.
To correct errors at F5 debug mode
• To execute the application from VS.NET, we click ‘Start
Debugging’. When application encounters a runtime
error, automatically a dialog box pops up and the line
which caused the error is indicated.
• Drag a textbox, button and a label. Lets us calculate
square of a number on clicking the button.
<script runat="server">
protected void Button1_Click(object sender,
EventArgs e){
int i =Int32.Parse( TextBox1.Text);
int sqr=i*i;
Label1.Text = " Square of the number is
" + sqr;
}
</script>
• Execute with the right inputs first.
• Now type incorrect value and see what happens.
Debugging icons
F5
Continue Stop Restart
Debugging Stored Procedures
• Database projects and SQL Debugging
facilities are available in VS professional
or Team Editions.
• Step Into facility can be used with VS to
debug stored procedures defined in SQL
server 2005.
• Break points can also be set in the stored
procedure and F5 could be used to
execute up to that point.
IIS Vs ASP.NET Development server
• The VS.NET come with a minimal server which is just a
subset of IIS. This sever is called ASP.NET Development
server.
• When F5 is pressed, if web.config is not present in the
web application, a dialog box automatically appears which
prompts to add web.config with debugging mode
enabled.
• As soon as this happens, the ASP.NET Development
Server starts and the browser window opens.
• As soon as the browser is close the application server
shuts down.
• Note that in case the application requires security context
such as anonymous users or a specific domain user IIS
must be use.
We will encounter this in security section