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.
I have also noticed this also and it has burned me big-time. This has got to be a major bug in VS. I have found that it only executes that 'block' of code it is in after you stop the Debugger. If somebody knows a way to stop the Debugger on the line
it is stopped on, PLEASE let me know. This is very dangerous. I actually noticed it in VS 2003 also when I used IIS - and I also notice it now when in VS 2005 using the development server.
It's good to know that someone else has experienced this issue. It stops you thinking that you are going mad or that there is something wrong with your PC's setup.
I tried it too ,am facing the same issue , must be a bug associated with the debugger of Visual Studio 2005. This is a cool bug found in Visual Studio 2005 [;)]
This still happens in Visual Studio 2008 (VS2008). They should really publicize this sort of thing. If you stop it just before executing code that updates a live database (thinking it won't do it) you can be in deep trouble when it updates the db anyway.
The only solution I found is to Set the Next line to execute to the last line of the function before hitting the
Stop Debugging button.
This is because by default, Visual Studio will detach from the ASP.NET process instead of terminating it. If you would prefer the debugger terminate the ASP.NET process, there is a 'Debug->Terminate All' menu item. I believe that this command is hidden by
default for some profiles, so you may need to switch to the general profile, or unhide this command to use it.
Alternatively, web application projects (File->New Project instead of File->New Web Site) have a project option to 'Enable Edit and Continue'. If you enable this option, the debugger will terminate the ASP.NET process as part of start debugging.
Gregg Miskelly
Visual Studio Debugger Developer
Gregg Miskelly
Visual Studio Debugger Dev
http://blogs.msdn.com/greggm/
Indeed, Using Terminate All kills off the Development Server therby making sure the code does not continue to execute.
You second idea of using a Web application project instead of a Web site project means radically changing the way you develop your site so I'm not sure this is suitable to solve the problem discussed.
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
Mikhail Arkh...
All-Star
33139 Points
6083 Posts
Microsoft
Re: Stop Debugging Command Doesn't Stop Execution
Feb 07, 2007 02:26 PM|LINK
Are you using IIS or development server?
------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
buggerlugs
0 Points
3 Posts
Re: Stop Debugging Command Doesn't Stop Execution
Feb 07, 2007 03:27 PM|LINK
johnpavelka
Member
485 Points
141 Posts
Re: Stop Debugging Command Doesn't Stop Execution
Mar 29, 2007 05:17 PM|LINK
I have also noticed this also and it has burned me big-time. This has got to be a major bug in VS. I have found that it only executes that 'block' of code it is in after you stop the Debugger. If somebody knows a way to stop the Debugger on the line it is stopped on, PLEASE let me know. This is very dangerous. I actually noticed it in VS 2003 also when I used IIS - and I also notice it now when in VS 2005 using the development server.
buggerlugs
0 Points
3 Posts
Re: Stop Debugging Command Doesn't Stop Execution
Mar 30, 2007 08:34 AM|LINK
It's good to know that someone else has experienced this issue. It stops you thinking that you are going mad or that there is something wrong with your PC's setup.
Regards,
Buggerlugs
toenee
Member
2 Points
1 Post
Re: Stop Debugging Command Doesn't Stop Execution
Aug 30, 2007 08:34 PM|LINK
Hi there,
Has anyone found a workaround for this?
Thanks,
-Tony
keerti_somu
Member
14 Points
7 Posts
Re: Stop Debugging Command Doesn't Stop Execution
Sep 17, 2007 09:27 AM|LINK
I tried it too ,am facing the same issue , must be a bug associated with the debugger of Visual Studio 2005. This is a cool bug found in Visual Studio 2005 [;)]
Thanks & Regards
Keerti Somasundaram
Keerti Somasundaram
adinas
Member
15 Points
9 Posts
Re: Stop Debugging Command Doesn't Stop Execution
Feb 05, 2008 08:50 AM|LINK
This still happens in Visual Studio 2008 (VS2008). They should really publicize this sort of thing. If you stop it just before executing code that updates a live database (thinking it won't do it) you can be in deep trouble when it updates the db anyway.
The only solution I found is to Set the Next line to execute to the last line of the function before hitting the Stop Debugging button.
greggm
Member
58 Points
11 Posts
Re: Stop Debugging Command Doesn't Stop Execution
Feb 06, 2008 12:32 AM|LINK
This is because by default, Visual Studio will detach from the ASP.NET process instead of terminating it. If you would prefer the debugger terminate the ASP.NET process, there is a 'Debug->Terminate All' menu item. I believe that this command is hidden by default for some profiles, so you may need to switch to the general profile, or unhide this command to use it.
Alternatively, web application projects (File->New Project instead of File->New Web Site) have a project option to 'Enable Edit and Continue'. If you enable this option, the debugger will terminate the ASP.NET process as part of start debugging.
Gregg Miskelly
Visual Studio Debugger Developer
Visual Studio Debugger Dev
http://blogs.msdn.com/greggm/
adinas
Member
15 Points
9 Posts
Re: Stop Debugging Command Doesn't Stop Execution
Feb 07, 2008 12:37 PM|LINK
Indeed, Using Terminate All kills off the Development Server therby making sure the code does not continue to execute.
You second idea of using a Web application project instead of a Web site project means radically changing the way you develop your site so I'm not sure this is suitable to solve the problem discussed.
Adin