all groups > sql server programming > september 2007 >
You're in the

sql server programming

group:

Return Error Code


Re: Return Error Code Alex Kuznetsov
9/23/2007 5:51:51 PM
sql server programming:
[quoted text, click to view]

It is best practice to return error code, as demonstrated in the
following code:

CREATE PROCEDURE dbo.run_DTS
/*
Runs update_db_dts DTS job using shell method
*/
AS
DECLARE @shell varchar(255), @error INT
SET @shell = 'dtsrun /S PCGOADFILE /N "update_db_dts"/U "sa" /P
"password"'
exec @error = master..xp_cmdshell @shell
return @error
GO

DECLARE @ret INT
EXEC @ret = dbo.run_DTS
Return Error Code scott
9/23/2007 7:39:58 PM
My sproc below should run a DTS job. The problem I'm having is with the
"error returning" part. When I try to test it from QA, by typng

"exec run_DTS"

I get an error saying "Procedure 'run_DTS' exxpects parameter '@error',
which was not supplied"

I'm not well versed at adding return codes in sprofs, can someone tell me if
i'm writing my sproc correctly to return an error code if my dts job is
successful or unsuccessful and also how I should execute the sproc from QA?


CODE: *************************

CREATE PROCEDURE run_DTS
/*
Runs update_db_dts DTS job using shell method
*/
(
@error bit OUTPUT
)
AS
DECLARE @shell varchar(255)
SET @shell = 'dtsrun /S PCGOADFILE /N "update_db_dts"/U "sa" /P "password"'
exec @error = master..xp_cmdshell @shell
return @error
GO

Re: Return Error Code Adi
9/24/2007 1:55:57 AM
[quoted text, click to view]

If you want to use output parameter, you have to pass it to the stored
procedure and define the parameter as an output parameter. Using
your example, your code should look like this:

DECLARE @Err bit
EXEC run_DTS @Err output

Adi
AddThis Social Bookmark Button