SQL Server Management Studio (SQL Server 2005) Express how to debug store procedure

I do not see a debug option within sql server manager studio to allow me to break within a stored procedure.  Is it a versioning issue, a setting,  or I am just not finding it?

Thanks in advice,
Howard
LVL 1
Howard BashSenior Software EngineerAsked:
Who is Participating?
 
8080_DiverConnect With a Mentor Commented:
I wasn't necessarily talking about walking from the VS Solution into the SP.  What I was saying is that you can open the SP in VS and execute the SP from VS.  It lets you set up the parameters and then, I believe 9it's been a little bit since I was doing it ;-), you can step into the SP and have break points that let you check things.  However, I generally use PRINT to output things along the way and I watch the OUTPUT tab.
I also advise creating and debugging the SP's behind the SELECT, INSERT, UPDATE, and DELETE functionalities prior to actually cranking them up in the Solution's gridview.
0
 
8080_DiverCommented:
I would recommend working in Visual Studio instead of Management Studio.  Among other things, I find the way VS works with SP's to be much more intuitive and much easier to work with.
I believe you can set break points in the SP in VS.
0
 
Howard BashSenior Software EngineerAuthor Commented:
That sounds good also.  I am using a gridview with an sqldatasource for selects, edits, and deletes and stepping from the update click into the stored procedure would be great.  What are the steps to round trip from clicking the update button on a grid to breakpointing in a stored procedure which is sitting on  a server waiting to execute?   How do I set the up in my vs2005 project?

Thanks.

0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
Howard BashSenior Software EngineerAuthor Commented:
In the name of trying to debug from within VS2005,  I have been trying to add an sql server (not my local sql express) as a data connection and cannot seem to get to a dialog for connecting to a remote sql server.  I only see a browse to an sql server data file.

Can you clue me in as to how to connect my sql server to vs2005 to let me debug as you suggest above?

Thanks.
0
 
Jim P.Commented:
Talking through my hat -- most likely M$ crippled the SSMS Express just like they crippled Visual Studio Express. The VSE makes you jump through hoops to connect to a full blown remote SQL Server Standard. Probably the same issue here.
0
 
Mark WillsTopic AdvisorCommented:
Debugging a SP in a query window is not too bad, just a bit manual...

e.g. suppose I right clicked on my SP and selected Script SP as; Create to; New query Window - I would get new window with my sp something like :

create procedure usp_My_liddle_bewdy(@p1 varchar(60), @p2 int, @p3 datetime)
as
begin

       if @p1 is NULL return

       declare @date datetime
       declare @order int
       declare @customername varchar(60)
       declare @ordervalue money
       declare @orderdiscount money

       set @date = isnull(@p3,getdate())
       set @order = isnull(@p2,0)
       set @customername = @p1

       if exists (select @customername from tbl_frequent_buyer_program)
       begin

             set @ordervalue = (select sum(orderamount) from tbl_my_orders where ordernum = @order and orderdate <= @date)
             set @orderdiscount = case when isnull(@ordervalue,0) < 1000 then @ordervalue * 0.10 else @ordervalue * 0.20 end

       end

       select @orderdiscount as loyalty_discount

end
go


then the way to debug it is pretty straight forward - use the print and/or select command... Comment out the definition of the procedure and insert the commands as necesary, and then it is a straight query...
 
the reason I use the "script sp as create to new query window" is so it will not be recreated if accidentally run (already exists therefore fails"


--create procedure usp_My_liddle_bewdy(@p1 varchar(60), @p2 int, @p3 datetime)
--as
--begin

-- debug
declare @p1 varchar(60), @p2 int, @p3 datetime
set @p1 = 'my test values'

       if @p1 is NULL return

       declare @date datetime
       declare @order int
       declare @customername varchar(60)
       declare @ordervalue money
       declare @orderdiscount money

       set @date = isnull(@p3,getdate())
       set @order = isnull(@p2,0)
       set @customername = @p1

select '>> Step 1 - values <<', @date, @order, @customername

       if exists (select @customername from tbl_frequent_buyer_program)
       begin

select '>> Step 2 - found <<', @customername

             set @ordervalue = (select sum(orderamount) from tbl_my_orders where ordernum = @order and orderdate <= @date)
             set @orderdiscount = case when isnull(@ordervalue,0) < 1000 then @ordervalue * 0.10 else @ordervalue * 0.20 end

select '>> Step 3 - Order Totals <<', @customername, @ordervalue, @orderdiscount

       end

select '>> Step 4 - return values <<"

       select @orderdiscount as loyalty_discount

--end
--go



then when I find the error, can fix, annotate, remove all the debug stuff and then "alter" the procedure.

Bit manual, bit fiddley but easy to do and easy to put in SQL command to helop identify the real problem...
0
 
Mark WillsConnect With a Mentor Topic AdvisorCommented:
If you can show the stored procedure and describe the problem, might be able to help a bit more.

But stepping through in debug mode is not really an option for you without a lot of pain and headache. Avoid the pain and headache and simply run the procedure as a query with the appropriate diagnostic information.
0
 
Howard BashSenior Software EngineerAuthor Commented:
I don't see debugging available in management studio.  Is there some special setup that I must perform to have debugging available in that environment?
0
 
Mark WillsTopic AdvisorCommented:
If you really must use the debugger, in SQL2008 have a read of : http://msdn.microsoft.com/en-us/library/cc646024.aspx

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.