March 3, 2006 at 3:51 am
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
March 3, 2006 at 5:36 am
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
March 3, 2006 at 6:39 am
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
March 3, 2006 at 7:01 am
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.
March 3, 2006 at 7:16 am
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
March 3, 2006 at 11:26 am
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
March 5, 2006 at 11:45 pm
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
March 5, 2007 at 3:06 am
try use osql -b
Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy