>This is a standard procedure I am using to backup a SQL Server database:
>
>
> Public Function Backup() As Boolean
> Dim loBackup As Backup = New Backup
> Dim loServer As Server = New Server
>
> oOriginator.Status.Text = "Backing up database..."
>
> loBackup.Devices.AddDevice("D:\Data\Optic.bak", DeviceType.File)
> loBackup.Database = "Optic"
> loBackup.Action = Microsoft.SqlServer.Management.Smo.BackupActionType.Database
> loBackup.Initialize = True
> loBackup.PercentCompleteNotification = 1
> AddHandler loBackup.PercentComplete, AddressOf ProgressEventHandler
> loBackup.SqlBackup(loServer)
>
> Return True
> End Function
>
> Private Sub ProgressEventHandler(ByVal sender As Object, ByVal e As PercentCompleteEventArgs)
> oOriginator.Status.Text = "Backing up database: " + e.Percent.ToString + "% completed..."
> Application.DoEvents()
> End Sub
>
>
>Basically, to adapt it to a new environment, I simply change the loBackup.Devices.AddDevice line with the path and database name I wish to have and the loBackup.Database line to specify the database. However, in one particular environment, this code doesn't work. The error says that the backup failed. There is no more information. That server is SQL Server 2008, such as many other servers I have run this procedure into. Once I installed the SMO objects to be able to manipulate that remotely, I was able to have the code to execute up until the loBackup.SqlBackup(loServer). Does anyone know what kind of setting locally would affect it so it woudn't work?
Did you try to put loBackup.SqlBackup(loServer) into try/catch and examine the exception message ?
If it's not broken, fix it until it is.
My Blog