Home All Groups Group Topic Archive Search About
Author
1 Mar 2006 10:58 PM
Pablo Montilla
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello, I'm executing the following command line inside a .cmd file:

osql -E -S .\sqlexpress -b -n -d DBName -i commands.sql
if %errorlevel% neq 0 goto error
goto end
:error
echo Something went wrong...
:end

But if I get an error in the commands.sql execution, I don't get an
errorlevel different from 0.

What I'm doing wrong?

Thanks,
Pablo

- --
Pablo Montilla
www.odyssey.com.uy

There was an item in the paper today. A lion got loose in the Central Park
Zoo. And was severely mauled.
-- Bob Newhart


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32)

iD8DBQFEBicYvooSiBfQCSoRApjFAKDn+YG+XYB8vhUCuRmKLkY7bYyuqgCgyPdr
8a2l9jYPgDifrE3ERYIIDMg=
=qZTZ
-----END PGP SIGNATURE-----

Author
1 Mar 2006 11:22 PM
Erland Sommarskog
Pablo Montilla (mel***@odyssey.com.uy) writes:
>
> Hello, I'm executing the following command line inside a .cmd file:
>
> osql -E -S .\sqlexpress -b -n -d DBName -i commands.sql
> if %errorlevel% neq 0 goto error
> goto end
>:error
> echo Something went wrong...
>:end
>
> But if I get an error in the commands.sql execution, I don't get an
> errorlevel different from 0.

You need to control this from the script. You can use EXIT() or RAISERROR
with state 127. This is discussed in Books Online in the topic for OSQL.

--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Author
1 Mar 2006 11:28 PM
Pablo Montilla
Erland Sommarskog wrote:
Show quote
> Pablo Montilla (mel***@odyssey.com.uy) writes:
>> Hello, I'm executing the following command line inside a .cmd file:
>>
>> osql -E -S .\sqlexpress -b -n -d DBName -i commands.sql
>> if %errorlevel% neq 0 goto error
>> goto end
>> :error
>> echo Something went wrong...
>> :end
>>
>> But if I get an error in the commands.sql execution, I don't get an
>> errorlevel different from 0.
>
> You need to control this from the script. You can use EXIT() or RAISERROR
> with state 127. This is discussed in Books Online in the topic for OSQL.
>
OK. Many thanks.

Pablo
--
Pablo Montilla
www.odyssey.com.uy

"They that love beyond the world cannot be
separated by it.  Death is but crossing the world,
as friends do the seas; they live in one another
still."
-- William Penn

AddThis Social Bookmark Button