I am in the process of automating SQL DB backups via VBA - I'm currently outputting the following SQL verification command as an .SQL script to check if a database has completed the backup (and launching SQL Query Analyzer from command line):
However, if the database hasn't fully compiled (thus failing verification) it returns this error:
So my request is how can I return this error info back into Excel, so it will just loop the original RESTORE command until the database has fully compiled.
Code:
RESTORE VERIFYONLY FROM DISK = 'DATABASE.bak'
However, if the database hasn't fully compiled (thus failing verification) it returns this error:
Code:
Server: Msg 3201, Level 16, State 2, Line 1
Cannot open backup device 'database.bak'.
Device error or device off-line. See the SQL Server error log for more details.
Server: Msg 3013, Level 16, State 1, Line 1
VERIFY DATABASE is terminating abnormally.
So my request is how can I return this error info back into Excel, so it will just loop the original RESTORE command until the database has fully compiled.