Pongo a dispocision de la comunidad 2 metodos que me resultan muy utiles, tanto como para respaldar como para restaurar una base de datos.
Solo deben agregar una referencia a Microsoft SQLDMO Object Library, este procedimiento solo sirve para sql 2000.
Código:
Public Function MakeBackup(strServerName As String, strDBName As String, _
strLogin As String, strPassword As String, strBackupFileName As String) As Boolean
On Error GoTo ManipularError
Dim oSQLServer As New SQLDMO.SqlServer
Dim oSQLBackup As New SQLDMO.Backup
oSQLServer.LoginSecure = True
Call oSQLServer.Connect(strServerName, strLogin, strPassword)
oSQLBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database
oSQLBackup.Database = strDBName
oSQLBackup.Files = strBackupFileName
oSQLBackup.SQLBackup oSQLServer
MakeBackup = True
Set oSQLServer = Nothing
Set oSQLBackup = Nothing
Exit Function
ManipularError:
Set oSQLServer = Nothing
Set oSQLBackup = Nothing
Err.Raise Err.Number, "MakeBackup()" & vbCrLf & Err.Source
End Function
Public Function MakeRestore(strServerName As String, strDBName As String, _
strLogin As String, strPassword As String, strBackupFileName As String) As Boolean
On Error GoTo ManipularError
Dim oSQLServer As New SQLDMO.SqlServer
Dim oSQLRestore As New SQLDMO.Restore
oSQLServer.LoginSecure = True
Call oSQLServer.Connect(strServerName, strLogin, strPassword)
oSQLRestore.Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database
oSQLRestore.Database = strDBName
oSQLRestore.Files = strBackupFileName
oSQLRestore.SQLRestore oSQLServer
MakeRestore = True
Set oSQLServer = Nothing
Set oSQLRestore = Nothing
Exit Function
ManipularError:
Set oSQLServer = Nothing
Set oSQLRestore = Nothing
Err.Raise Err.Number, "MakeRestore()" & vbCrLf & Err.Source
End Function Modo de uso, solo de referencia:
Código:
Call MakeBackup("(local)", "Northwind", "sa", "1234", "C:\backups\Northwind.bak") Saludos y espero les sirva.