Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How can I get the DOS ERRORLEVEL use osql -b???

Author  Topic 

sysbob
Starting Member

2 Posts

Posted - 2004-10-25 : 01:27:29
the help document said that

"osql -b will specifies that OSQL exits and returns a DOS ERRORLEVEL value when an error occurs. The value returned to the DOS ERRORLEVEL variable is 1 when the SQL Server error message has a severity of 10 or greater; otherwise, the value returned is 0."

my question is : how can I get the DOS ERRORLEVEL.

example:

C:\>isql -E -b -Q"backup log pubs to disk='C:\adsfasd.tmp'"

the result:

Msg 4208, Level 16, State 0, Server YANG, Line 1
µ±»Ö¸´Ä£ÐÍΪ SIMPLE ʱ£¬²»ÔÊÐíʹÓà BACKUP LOG Óï¾ä¡£ÇëʹÓà BACKUP DATABASE »òÓÃ
ALTER DATABASE
¸ü¸Ä»Ö¸´Ä£ÐÍ¡£
Msg 3013, Level 16, State 1, Server YANG, Line 1
BACKUP LOG ²Ù×÷Òì³£ÖÕÖ¹¡£

It's in chinese language,means
"can not use BACKUP LOG when the restore model being SIMPLE,you can use ALTER DATABASE or BACKUP DATABASE to change the restore model.
Msg 3013, Level 16, State 1, Server YANG, Line 1
BACKUP LOG aborted"

where is DOS ERRORLEVEL???? How can I get it????

thanks

Kristen
Test

22859 Posts

Posted - 2004-10-25 : 01:31:19
Make a MyFilename.BAT file:

@ECHO OFF
osql -E -b -Q"backup log pubs to disk='C:\adsfasd.tmp'"
IF ERRORLEVEL 1 GOTO GotError
ECHO Processed OK
GOTO END
:GotError
ECHO Error Occurred

... put any other error handling logic here ...

:END
ECHO.

Kristen
Go to Top of Page
   

- Advertisement -