November 24, 2005 at 3:11 am
Have you got a script you could post for your 'DebugSP' proc? I am doing something now where this would be extremely useful? =)
November 24, 2005 at 2:17 pm
Here is a conceptual look at one
All you need to do is fill in the bits. I've borrowed some of the stuff Dave talked about in his article and just layed out the concept for you.
Apply your own standards and away you go.
CREATE PROCEDURE lsp_Debug
(
@dtStart DATETIME
, @dtEnd DATETIME
-- Variable list here
)
AS
DECLARE @ReturnCode INT
BEGIN
-- Set the default return value to success
SELECT @ReturnCode = 0
IF EXISTS ( SELECT
1
FROM
debug_control
WHERE
dbg_can_debug = 1
)
BEGIN
-- Calculate time elapsed if you have an end date as well as a start date
-- Send message to event log so even if a rollback occurs we can see how far we got
DECLARE @sStringVar VARCHAR(440)
, @lInteger INT
, @fFloat DECIMAL(6,2)
, @byUnsignedInt TINYINT
SELECT
@sStringVar = 'A string'
, @lInteger = 44
, @fFloat = 3.14
, @byUnsignedInt = 56
RAISERROR('The string variable contains %s, the int contains %d, the float contains %d, the uint contains %d'
, 10 -- Informational severity only.
, 1
, @sStringVar
, @lInteger
, @fFloat
, @byUnsignedInt
) WITH LOG
, NOWAIT
INSERT dbo.debug_log
(
-- Add apropriate columns here
)
SELECT
-- Select approapriate data here
FROM
-- Use from if you want to peek at data being processed
-- Check for any errors
SELECT @ReturnCode = @@ERROR
END
-- Return any errors found along the way
RETURN @ReturnCode
END
GO
Hope you find this useful, sorry I don't have more time to flesh it out for you.
November 24, 2005 at 3:02 pm
Thanks very much
November 28, 2005 at 5:07 am
Thanks for a useful and clear article - much appreciated.
One comment: as an initial step the SQL profiler can also be useful - no coding required! Of course you cannot see how the parameters flow through the procedure, but the various statements it executes may give an indication of the program flow.
May 23, 2006 at 3:36 pm
excellect opps
October 23, 2008 at 9:31 am
Is it possible to log the RAISERROR messages into a table and not just to the Windows Even Log?
I've some stored procedures with the following line:
RAISERROR(@Message,10,1) WITH NOWAIT
and I'd like to have all this in a table without the need to modify it. So, the solution told by Steve about using a stored procedure like lsp_Debug couldn't be used.
Maybe in the way to execute it?
February 15, 2012 at 12:51 pm
Richard Moldwin (11/23/2005)
T-SQL programming involves a major loss of productivity, compared to any other modern language I know of.
I know it's a wicked old post but the comment above is just so very wrong. It's like anything else... you have to know how to use the tool correctly in order to be productive with it.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 16 through 21 (of 21 total)
You must be logged in to reply to this topic. Login to reply