I am running an osql using input script which runs a database backup. Is
there a way I could get a return of 1 or 0, 0 being success and 1 being
error. I tried using -b option but it returns the entire details of failure
followed by the return number and if i use -o paramater I dont see any
result at all. Can anyone please suggest some solution to this. any help
will be greatly appreciated. Thanks
Message posted via http://www.webservertalk.comTry catching the error in the batch being executed with OSQL and use
RAISERROR to set the DOS variable ERRORLEVEL.
Example:
Create a batch file with the following instructions:
osql -S my_server -E -d master -Q "backup database northwind to blahblah if
@.@.error != 0 raiserror ('Error during backup.', 16, 127)"
echo %ERRORLEVEL%
Execute the batch file and you will see 50000 as the echo of the variable
ERRORLEVEL, because I am specifying a msg_str in RAISERROR. You can create
your own error msg using sp_addmessage.
AMB
"ishaan99 via webservertalk.com" wrote:
> I am running an osql using input script which runs a database backup. Is
> there a way I could get a return of 1 or 0, 0 being success and 1 being
> error. I tried using -b option but it returns the entire details of failur
e
> followed by the return number and if i use -o paramater I dont see any
> result at all. Can anyone please suggest some solution to this. any help
> will be greatly appreciated. Thanks
> --
> Message posted via http://www.webservertalk.com
>|||I forgot to mention that in order to set DOS variable ERRORLEVEL, using
RAISERROR, you have to specify state 127.
Error Handling in SQL Server – a Background
http://www.sommarskog.se/error-handling-I.html
Implementing Error Handling with Stored Procedures
http://www.sommarskog.se/error-handling-II.html
AMB
"Alejandro Mesa" wrote:
> Try catching the error in the batch being executed with OSQL and use
> RAISERROR to set the DOS variable ERRORLEVEL.
> Example:
> Create a batch file with the following instructions:
> osql -S my_server -E -d master -Q "backup database northwind to blahblah i
f
> @.@.error != 0 raiserror ('Error during backup.', 16, 127)"
> echo %ERRORLEVEL%
> Execute the batch file and you will see 50000 as the echo of the variable
> ERRORLEVEL, because I am specifying a msg_str in RAISERROR. You can create
> your own error msg using sp_addmessage.
>
> AMB
>
> "ishaan99 via webservertalk.com" wrote:
>|||Thanks so much. That helped and worked fine.
Message posted via http://www.webservertalk.com
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment