Using the return value of a SQL Restore script

Tags:
SQL
SQL Restore
SQL Server
I am trying to use the return value of a SQL Restore script executed with SQLCMD, so that my batch script can report on the succes or failure of the restore. I am having difficulty getting the script to return the result of the backup or restore process. Do you have any suggestions? The follwoing succesfully restores the database but returns a -100 error code:
SQLCMD -S SERVERNAME -Q "exit(RESTORE DATABASE [PremiumAutomation] FROM  DISK = N'C:SQLBackupsHotBackupPremiumAutomationRest.bak' WITH  FILE = 1,  NOUNLOAD,  REPLACE,  STATS = 10)" -o FolderNameRestore.Log

Answer Wiki

Thanks. We'll let you know when a new response is added.

You can use SQLCMD <b>-b</b> to return a nonzero exit code when the SQL batch fails.
You can then check the ERRORLEVEL in the batch to determine if the outcome was succesfull

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: