StormbringerX
Programmer
Hi Everyone,
I'm using VB6 SP6, sql2000, windows XP.
My application needs to make a copy of an existing database and place the copy under a new name.
I'm using sqldmo and my backup procedure is working great. THe problem comes in when I attempt to restore the database to a new name.
Essentially, I need to backup up an existing database, then restore it to another name so that the user can login into the new one, do some statistical analysis, whatif calculations, without damaging any online data. The destination database DOES already exist.
The code that I am using is straight from Microsoft SQLDMO VB examples. Ofcourse it has been modified somewhat. The server and database names are hardcoded at the moment for ease of debugging. Here is the code
Private Sub Restore()
On Error GoTo ErrHandler:
Dim oRestore As SQLDMO.Restore
Dim Msg As String
Dim Response As String
gDatabaseName = "sqlrack"
Set oRestore = New SQLDMO.Restore
Set oRestoreEvent = oRestore ' enable events
oRestore.Database = "whatif"
gBkupRstrFileName = "c:\swproperty.bak"
oRestore.Files = gBkupRstrFileName
oRestore.ReplaceDatabase = True
' Change mousepointer while trying to connect.
Screen.MousePointer = vbHourglass
' Restore the database.
oRestore.SQLRestore gSQLServer
' Change mousepointer back to the default after connect.
Screen.MousePointer = vbDefault
Set oRestoreEvent = Nothing ' disable events
Set oRestore = Nothing
Exit Sub
ErrHandler:
MsgBox "Error " & Err.Description
Resume Next
End Sub
As you can see, I want to backup a databse named: swproperty. This works well.
I want to restore a database named: whatif.
But the resore itself keeps attempting to restore it as swproperty.
Does anyone know of a way to restore to another name? I can't seem to find a applicable property.
Thanks for your time,
Dave
I'm using VB6 SP6, sql2000, windows XP.
My application needs to make a copy of an existing database and place the copy under a new name.
I'm using sqldmo and my backup procedure is working great. THe problem comes in when I attempt to restore the database to a new name.
Essentially, I need to backup up an existing database, then restore it to another name so that the user can login into the new one, do some statistical analysis, whatif calculations, without damaging any online data. The destination database DOES already exist.
The code that I am using is straight from Microsoft SQLDMO VB examples. Ofcourse it has been modified somewhat. The server and database names are hardcoded at the moment for ease of debugging. Here is the code
Private Sub Restore()
On Error GoTo ErrHandler:
Dim oRestore As SQLDMO.Restore
Dim Msg As String
Dim Response As String
gDatabaseName = "sqlrack"
Set oRestore = New SQLDMO.Restore
Set oRestoreEvent = oRestore ' enable events
oRestore.Database = "whatif"
gBkupRstrFileName = "c:\swproperty.bak"
oRestore.Files = gBkupRstrFileName
oRestore.ReplaceDatabase = True
' Change mousepointer while trying to connect.
Screen.MousePointer = vbHourglass
' Restore the database.
oRestore.SQLRestore gSQLServer
' Change mousepointer back to the default after connect.
Screen.MousePointer = vbDefault
Set oRestoreEvent = Nothing ' disable events
Set oRestore = Nothing
Exit Sub
ErrHandler:
MsgBox "Error " & Err.Description
Resume Next
End Sub
As you can see, I want to backup a databse named: swproperty. This works well.
I want to restore a database named: whatif.
But the resore itself keeps attempting to restore it as swproperty.
Does anyone know of a way to restore to another name? I can't seem to find a applicable property.
Thanks for your time,
Dave