When debugging the server-side code of my ASP page, if I stop debugging (via the 'Stop Debugging' option on the debug menu or the equivalent tool-bar button) although this appears to stop the debugging session, it actually executes the subsequent code.
(I am using Visual Studio 2005 SP1 and IE7, running under Windows XP Professional.)
Steps to reproduce the issue:
1. Create a new table in your SQL Server database called 'Table1', containing a varchar(50) column called 'Column1'.
2. Create a new ASP.Net web site (using C#).
3. Add an ASP button control to the 'Default.aspx' page and double-click it to create the event handler.
4. Add a reference to the 'System.Data.SQLClient' namespace.
5. Paste the following routine into the 'Default.aspx.cs' file:
private bool AddRecord()
{
SqlConnection cnn = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=YourDB;Data Source=(local)");
SqlCommand cmd = new SqlCommand("INSERT INTO Table1 (Column1) VALUES ('This record should not exist')", cnn);
cmd.CommandType = CommandType.Text;
(You will have to adjust the connection string as appropriate for your database.)
6. Add a call to the 'AddRecord' function into the 'Button1_Click' function like so:
protected void Button1_Click(object sender, EventArgs e)
{
AddRecord();
}
7. Put a breakpoint anywhere before the line 'cmd.ExecuteNonQuery();'.
8. Run the project in debug and when it hits the breakpoint - stop it.
9. Examine the contents of Table1, it should have a record in it, despite the fact that the SQL insert command should not have been executed.
buggerlugs
0 Points
3 Posts
Stop Debugging Command Doesn't Stop Execution
Feb 07, 2007 09:43 AM|LINK
When debugging the server-side code of my ASP page, if I stop debugging (via the 'Stop Debugging' option on the debug menu or the equivalent tool-bar button) although this appears to stop the debugging session, it actually executes the subsequent code. (I am using Visual Studio 2005 SP1 and IE7, running under Windows XP Professional.)
Steps to reproduce the issue:
1. Create a new table in your SQL Server database called 'Table1', containing a varchar(50) column called 'Column1'.
2. Create a new ASP.Net web site (using C#).
3. Add an ASP button control to the 'Default.aspx' page and double-click it to create the event handler.
4. Add a reference to the 'System.Data.SQLClient' namespace.
5. Paste the following routine into the 'Default.aspx.cs' file:
private bool AddRecord()
{
SqlConnection cnn = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=YourDB;Data Source=(local)");
SqlCommand cmd = new SqlCommand("INSERT INTO Table1 (Column1) VALUES ('This record should not exist')", cnn);
cmd.CommandType = CommandType.Text;
try
{
cnn.Open();
cmd.ExecuteNonQuery();
cnn.Close();
}
catch (Exception ex)
{
return false;
}
return true;
}
(You will have to adjust the connection string as appropriate for your database.)
6. Add a call to the 'AddRecord' function into the 'Button1_Click' function like so:
protected void Button1_Click(object sender, EventArgs e)
{
AddRecord();
}
7. Put a breakpoint anywhere before the line 'cmd.ExecuteNonQuery();'.
8. Run the project in debug and when it hits the breakpoint - stop it.
9. Examine the contents of Table1, it should have a record in it, despite the fact that the SQL insert command should not have been executed.
.Net 2.0 postback asp.net 2.0 debug asp 2.0 Bug server side stop debugging