Returning SQL Error Codes back into Excel

pricer

New Member
Joined
Mar 21, 2007
Messages
25
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):

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.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
If you are using an ADODB connection to run the backups, then the Connection object has an Errors collection and there is a Description property for the individual Error objects. I can't say whether it would contain the information you require though, as I've never need to backup a db from VBA.
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,823
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top