What are the challenges you face when working across database platforms? Take the survey

Using exitcodes / sql error codes in scripts

randyjrandyj Posts: 48
edited June 27, 2006 5:17PM in SQL Backup Previous Versions
Could someone post an example of using exitcodes / sql error codes in a backup script ? I'm having difficulty with my syntax.

Thanks !


  • Options
    peteypetey Posts: 2,358 New member
    DECLARE @exitcode int 
    DECLARE @sqlerrorcode int 
    EXEC master..sqlbackup '-sql "BACKUP ..."', @exitcode OUTPUT, @sqlerrorcode OUTPUT 
    IF (@exitcode <> 0) OR (@sqlerrorcode <> 0) 
      RAISERROR ('SQL Backup step failed: exit code %d, SQL error code: %d', 16, 1, @exitcode, @sqlerrorcode) 
    Peter Yeoh
    SQL Backup Consultant Developer
    Associate, Yohz Software
    Beyond compression - SQL Backup goodies under the hood, updated for version 8
  • Options
    Thanks, Peter...
    Just what I needed!
Sign In or Register to comment.