Sunday, March 11, 2012

Displaying Print Debugging from Stored Procedure immediately

I am attempting to debug a very long stored procedure, for this I inserted many print statements at key points on the procedure, but I find that once I do an exec sp_name I only get the print statements show in the message tab only after the full execution or cancellation of the stored procedure.

Is there any way to force the message tab to display the messages mid execution?

One way is to use the raiserror command with a severity of 10 and a "with nowait" option. This will not cause an actual error to be raised, as you can see by running this code:

begin try

raiserror('Progress message', 10, 1) with nowait

end try

begin catch

print 'here'

end catch

Ron Rice

No comments:

Post a Comment