Osql error trapping

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tina888
    New Member
    • Sep 2007
    • 2

    Osql error trapping

    I am running osql command that goes and grabs files from my folder and runs one script at a time and loops though all the files in that folder. Most of the files and simple inserts or creation of stored procedures.


    Problem is that I want to exit out from osql if there is any error encountered while runing the script..


    I am using following command

    Cursor--

    SELECT @cmdstr = 'osql -E -S ' + @servername + ' -d ' + @dbname + ' -n -i ' + @input_full_pat h -- ' >> ' + @outputfile

    --show script processing
    PRINT 'Processing script: ' + @scriptname + '..'

    -- Cursor - go grab next file from folder

    I tried

    EXEC @errorstate=mas ter.dbo.xp_cmds hell @cmdstr
    print @errorstate
    IF @errorstate<>0
    BEGIN
    CLOSE crs_scripts
    DEALLOCATE crs_scripts
    RAISERROR('xp_c mdshell returned error while running script: %s', 15,3,@scriptnam e)
    RETURN
    END

    but it only takes care of osql specific errors and not the actual script run time error..

    Please help ...
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    1. What version are you using?

    2. Which part of the script you want to trap the error?

    -- CK

    Comment

    Working...