Return status to SP

  • If a backup is done as part of a stored procedure is there a way to get the result of the backup process back as either pass / fail or at least the output that would have gone to the console?

    I have tried a few methods utilising EXEC and sp executesql using local variables defined as output parameters but nothing seems to work - mostly the line throws an error.

    Lines such as

    SET @Path = 'E:\SQLBackup\MyDB_11111.bak'

    SET @SQLcmd = 'BACKUP DATABASE ' + 'MyDb' + ' TO DISK = ' + @Path

    SELECT @Result = EXEC @SQLCmd

    OR

    SELECT @Result = EXEC sp_executesql @SQLcmd

    OR

    EXEC sp_executesql @SQLcmd, @RetDef, @RetParam, @Result OUT

    Simply result in errors, I have tried these commands every which way around, anyone have any suggestions ... I need to know if the backup succeeded or not ....

  • hi

    just a thought - would it help to use @@ERROR variable just after your "EXEC" statement.

    "Keep Trying"

  • Why didn't I think of that ... why is it the simple solutions always evade me ???

    That works ...

    Doesn't explain why stepping through in debug mode throws error 3013 but the script runs fine in runtime but thats another question.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply