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)
 dos ERRORLEVEL problems

Author  Topic 

blakmk
Starting Member

45 Posts

Posted - 2002-12-20 : 05:39:28
Im having problems with dos ERRORLEVEL. Basically im running sqlserver scripts which return an ERROLEVEL != 0 if an error occurs.

If I run the scripts standalone and then check the error level it works but if I use a for loop to loop through a list of scripts supplied in a file the ERRORLEVEL always seems to be 0. This is the script i'm using:

SET UserName=DevUser
SET DatabaseName=MB_SCRIPT_TEST4
SET CreateDatabaseFlag=Y
SET DatabaseServername=Dev-Zeus
SET DriveLetter=c
SET SQLScriptDirectory=.\CreationScripts
SET SQLScriptList=SS7_RatingsDDLScriptList.txt
SET logfile=SS7_RatingsCreation.log

echo start >> %LogFile%
FOR /f %%f in (%SQLScriptDirectory%\%SQLScriptList%) DO (
ECHO Running %ISQLCmd%\%%f >> %LogFile%
isql /U %UserName% /E /n /S %DatabaseServerName% /d %DatabaseName% /b /i %SQLScriptDirectory%\%%f
echo isql /U %UserName% /E /n /S %DatabaseServerName% /d %DatabaseName% /b /i %SQLScriptDirectory%\%%f >> %Logfile%
ECHO error level is %ERRORLEVEL% >> %LogFile%
IF NOT %ERRORLEVEL%==0 (
ECHO Errorlevel %ERRORLEVEL%: Problem encountered in file %%f. Aborting database creation.
GOTO :ABORT
)
)


echo passed this far

GOTO :EOF

:ABORT

echo aborting


:EOF
echo ending


The logfile looks something like this:
Running \SQLServer7_RatingsCreationDDL_SequenceUpdateProc.sql
isql /U DevUser /E /n /S Dev-Zeus /d MB_SCRIPT_TEST4 /b /i .\CreationScripts\SQLServer7_RatingsCreationDDL_SequenceUpdateProc.sql
(1 row affected)
(1 row affected)
(1 row affected)
(1 row affected)
(1 row affected)
Msg 2627, Level 14, State 1, Server DEV-ZEUS, Line 21
Violation of PRIMARY KEY constraint 'PK__DatabaseConfig__571DF1D5'. Cannot
insert duplicate key in object 'DatabaseConfig'.
The statement has been terminated.
error level is 0
Running \SQLServer7_Ratings_UpdateScriptReleaseNumber.sql
isql /U DevUser /E /n /S Dev-Zeus /d MB_SCRIPT_TEST4 /b /i .\CreationScripts\SQLServer7_Ratings_UpdateScriptReleaseNumber.sql
Msg 2627, Level 14, State 1, Server DEV-ZEUS, Line 1
Violation of PRIMARY KEY constraint 'PK__DatabaseConfig__571DF1D5'. Cannot
insert duplicate key in object 'DatabaseConfig'.
The statement has been terminated.
(0 rows affected)
error level is 0


Any ideas how I can get around this?


   

- Advertisement -