ASV
13 years agoContributor
Restore database
Hi I need to restore database, which I am tesing. I write this- Set sql = CreateObject("SQLDMO.SQLServer") sql.LoginSecure = True sql.Connect cConnectionString Set sq...
'osql -S ' + ServerName + ' -U ' + UserID + ' -P ' + Password + ' -Q " RESTORE DATABASE ' + DBName + ' FROM DISK = ''' + Path + DBName+ '.BAK'' WITH REPLACE "' + ' -o "' + Project.Path + 'RestoreResult.txt"'
Piping the output to a result file allows us to check that the restore process succeeded by reading the file.
We access the command line via:
Sys.OleObject('WScript.Shell')
The only weakness we've found with this approach is that we do need to read the piped output file to check that the restoration succeeded, as the commandline interface will return 0 for successful to regardless of the outcome of the restore operation. If the restore was successful, the result file will contain the text "RESTORE DATABASE successfully processed" so it's relatively simple to use aqFile.ReadWholeTextFile to read the result into a string then search that string for the text and pass/fail based on whether it exists.
I hope that helps,
Kate