Using SQL-DMO to restore SQL databases 
Author Message
 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



Sat, 01 Nov 2003 04:42:03 GMT  
 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



Sat, 01 Nov 2003 04:41:59 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Restore database using SQL-DMO

2. Using Vbscript and SQL-DMO to connect to SQL Server and run a T-SQL script

3. SQL DMO (creating SQL Jobs/steps)

4. connect to sql server through sql-dmo

5. Another Problem with SQL-DMO and Transferring a Database

6. Question on Using SQL-DMO and Text fields

7. 2nd try - setting pk constraint using SQL-DMO

8. Using SQL-DMO to add jobs

9. Transfer storedprocs using VB & SQL-DMO

10. Transferring Tables using SQL-DMO

11. SQL DMO in VB-NET

12. SQL-DMO

 

 
Powered by phpBB® Forum Software