Hi everyone,
I have a cmd file that executes sql statements:
something like this:
Code Snippet
OSQL -S %sqlServer% -E -b -n -i DATABASE.sql"
IF ERRORLEVEL 1 GOTO error
echo -
...
:error
@.ECHO An error occured in [%errorLevel%]
echo [%errorLevel%] > %1
GOTO EXIT
if there is an error, I print the errorlevel in a txt file wich is a parameter in the command (%1)
What I want is: instead of sending the %errorlevel% to the txt, I want to send the error description but I don't know the variable that keeps the error description.
Any help please
Thanx in advance
I really need to know if there is some variable that gives me the sql error because when I execute the cmd, if there's an error
the error is printed int the cmd window.
The errorlevel var just give me the number "1" but I would like to get something like
"An error in database ocurred due to database already exists" or something like that.
Please I'll apreciate any ideias you may have
|||
Instead of overwriting the error log file, I would just append the error to the file instead.
Code Snippet
ECHO OFF
OSQL -S %sqlServer% -E -b -n -i test.sql > %1
IF ERRORLEVEL 1 GOTO error
ECHO "" > %1
EXIT
:error
@.ECHO An error occured in [%errorLevel%]
echo [%errorLevel%] >> %1
This way you either have a blank file, or you have a file with an error message and errorLevel code.
|||Thanx for the answer ShawnNWF, that will do the trick for sure