Saturday, November 1, 2008

Debugging stored procedures...

A while ago one of my friends told me about how she made a stored procedure and didn't debug it as she did not know how to, to which she had to hear "Yeh kaise programming hai?"

Hmmm so not knowing how to debug a stored procedure makes you a bad programmer.. huhh?

But whatever it means.. you should know how to do all the stuff that is provided in the softwares in order to fully explore the powers of the language being used.



So here I'll be talking about Debugging SQL stored procedures.

As I didn't know how to debug sps I too searched on the net and came up with many good articles.



Debugging stored procedures is very similar to debugging a function in Visual Studio. You set breakpoints, and then you execute the program in debug mode, whenever a breakpoint is hit the execution is paused so the developer can have a look at the current values of the variables etc.



I was thinking of writing the whole thing myself. But why waste my time and yours as well. I don't myself experienced enough to be writing all this. So I'll just put in the links that I found useful.



Debugging Stored Procedures in SQL Server 2000:



http://www.15seconds.com/Issue/050106.htm



This gives a detailed explanation of debugging stored procedures in SQL Server 2000.

I was only able to debug SPs from database that was on my own machine. I wasn't able to do the same by taking a connection from a database at a remote system. There must be some way of doing that but I don't know actually what that is. :)



Debugging Stored Procedures in SQL Server 2005:



http://aspnet.4guysfromrolla.com/articles/051607-1.aspx



In SQL Server 2005, you can't debug the stored procedures from within SQL Server 2005. But don't worry you can do it through Visual Studio 2005. I found this article pretty useful.

-------------

Do keep in mind that some people argue that using "PRINT" statement is much better than debugging. You can PRINT all the values you want to and let the procedure run normally, without debugging.But I would recommend that you give debugging a shot as well, and decide which one is better for you. It is also possible that in some situations debugging is just another headache you are buying for yourself, but in some situations it might prove to be very useful. In any case, as I said, you should know everything you can about a language or a software to exploit it's full power.

Happy Debuggin!! :)

No comments: