
Using SQL-DMO to restore SQL databases
Dear Friends,
I came accross a small problem and I thought that you'd be a great help. I'd
like to restore any SQL database from the file in VB, BUT I don't want the users
overwriting any databases except for one.
EX:
I have 5 databases: Master, Stage5, model, pubs, tempdb.
The user may back-up any one of those databases to a file on a disk.
But when it comes time to restore, all of those files MUST only be restored to
Stage5 database.(Stage5 may be over written as many times as needed.)
This is what I got in my COM DLL for restore:
Dim oRestore As SQLDMO.Restore
Set oRestore = CreateObject("SQLDMO.Restore")
Dim db As SQLDMO.SQLServer
Set db = CreateObject("SQLDMO.SQLServer")
With db
.LoginSecure = True
.Connect
End With
With oRestore
.Database = "Stage5"
.Action = SQLDMORestore_Database
.ReplaceDatabase = True
.Files = "c:\test.bak"
End With
Call oRestore.SQLRestore(db)
Set oRestore = nothing
set db = nothing
I can restore any database just fine. EXCEPT, i'd like to overwrite "Stage5"
database instead of the one that was backed-up.
SQL server stores the name of the database inside the back-up file(I'm
getting "Use WITH MOVE to identify a valid location for the file" error). How
would I override that?
I understand the whole purpose of restore is to restore the same database that
was backed-up. I just don't want the users overwritting current database with
old stuff.
Thank you very much in advance,
Vlad Orlovsky