How can we help you today? How can we help you today?

Using exitcodes / sql error codes in scripts

Could someone post an example of using exitcodes / sql error codes in a backup script ? I'm having difficulty with my syntax.

Thanks !
randyj
0

Comments

2 comments

  • petey
    Example:
    DECLARE @exitcode int 
    DECLARE @sqlerrorcode int 
    
    EXEC master..sqlbackup '-sql "BACKUP ..."', @exitcode OUTPUT, @sqlerrorcode OUTPUT 
    
    IF (@exitcode <> 0) OR (@sqlerrorcode <> 0) 
    BEGIN 
      RAISERROR ('SQL Backup step failed: exit code %d, SQL error code: %d', 16, 1, @exitcode, @sqlerrorcode) 
    END
    
    petey
    0
  • randyj
    Thanks, Peter...
    Just what I needed!
    randyj
    0

Add comment

Please sign in to leave a comment.