|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
SQLCMD errorlevel?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 anerrorlevel 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----- Pablo Montilla (mel***@odyssey.com.uy) writes:
> You need to control this from the script. You can use EXIT() or RAISERROR> 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. 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 Erland Sommarskog wrote:
Show quote > Pablo Montilla (mel***@odyssey.com.uy) writes: OK. Many thanks.>> 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. > 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 |
|||||||||||||||||||||||