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.
| 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=DevUserSET DatabaseName=MB_SCRIPT_TEST4SET CreateDatabaseFlag=YSET DatabaseServername=Dev-ZeusSET DriveLetter=cSET SQLScriptDirectory=.\CreationScriptsSET SQLScriptList=SS7_RatingsDDLScriptList.txtSET logfile=SS7_RatingsCreation.logecho 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 farGOTO :EOF:ABORTecho aborting:EOFecho endingThe 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 21Violation of PRIMARY KEY constraint 'PK__DatabaseConfig__571DF1D5'. Cannotinsert 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 1Violation of PRIMARY KEY constraint 'PK__DatabaseConfig__571DF1D5'. Cannotinsert 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? |
|
|
|
|
|