Yalçın Aktaş
Yalçın Aktaş

Reputation: 17

How to stop Visual Studio debugging so sql database changes not commit?

I work with several code pages and Stored Procedures during day. I look for an easy way to stop visual studio while debugging, so database changes rollback. Since I work with several pages, i don't want to add code for this in my pages or for every SP I use. Is there a shortcut or a command i can use in immediate window?(I am open to other solutions - these are the ones came into my mind) If I can manually throw an exception(not written in code, in immediate window may be, it may work.)

Upvotes: 1

Views: 989

Answers (3)

Rafał Straszewski
Rafał Straszewski

Reputation: 998

If you want to throw an exception, you can do it using Immediate Window, after hitting breakpoint.

The problem is, you can not use in Immediate Window something like:

throw new ApplicationException("Forced exception");

But you can create the method, and then launch it from Immediate Window

public static void ForceAnException()
{
    throw new ApplicationException("Forced exception");
}

In immediate window:

ForceAnException();

EDIT:

So maybe try this:

var throwEx = false;
if(throwEx) ForceAnException();

And change in immediate window throwEx to true, before condition is checked...it should work...

Upvotes: 0

usr
usr

Reputation: 171178

I usually kill the w3wp.exe process using Process Explorer. Alternatively, you can drag and drop the "yellow mark" in the debugger to a point after the commit so that the commit is skipped. I also sometimes set a variable to null and induce a crash that way.

Upvotes: 0

Sameer
Sameer

Reputation: 3183

I think the best thing is to use TransactionScope class for this.

Just wrap your db calls inside

 using (TransactionScope scope = new TransactionScope())
{
   // Invoke your database calls
   scope.Complete(); // Put a break point here and stop the program when the break point is hit.
}

Upvotes: 1

Related Questions