Return Code with isql, osql or isqlw

  • hi all

    how i get the return code from the command-line utilities isql,osql and isqlw. i want to apply a lot of scripts with an winndows command script and will terminate the batch if an sql-script endet with errors. the %errorlevel% is all times 0.

    any ideas

    thanks, guido

  • Google's a wonderful tool - I had pondered the same question but hadn't bothered looking for the answer until now...

    Anyhow, quick search on

    osql errorlevel

    gave the page

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/coprompt/cp_osql_1wxl.asp

    Read it - scroll down to Using EXIT to Return Results in osql - this will tell you exactly what you want to know..  Other handy hints in there too that I didn't know about (eg starting a line with !!).

    Cheers,

       Ian   

  • hi ian

    i have seen this article too, but..

    what i need is the return value by the following syntax:

    osql -S <server> -E -i <not_changeable_sql_script.sql> -o <output>

    so i can't use the EXIT keyword.

    thanks, guido

  • Try this

    osql -S <server> -E  -b -m-1 -i <not_changeable_sql_script.sql> -o <output>

    IF ERRORLEVEL 1 GOTO ERROR_LABEL

    Far away is close at hand in the images of elsewhere.
    Anon.

  • hi ian

    that's the big problem. osql don't return the return code. the errorlevel parameter is always zero, although the script failed.

    cheers, guido

  • Hi,

    try to play with output, when you are running from QA this

    create table Output(text varchar (100))

    insert into Output

    exec xp_cmdshell 'osql -S -dTEST_dev -i"D:\Data_load\TestScript.txt" -E'

    if exists(select * from Output where text like 'Cannot%')

    print 'Error!'

    --select * from Output where text like 'Cannot%'

    --delete from output

    Maybe that will help

     

  • hi all

    now, i iwork with a workaround. i read the output file and search any sql server messages. if no message found -> everything ok.

    thanks, guido

  • try use osql -b

Viewing 8 posts - 1 through 7 (of 7 total)

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