Imports Microsoft.SqlServer.Management.Smo
Public Class Form1
  Private Sub Form1_Load(ByVal sender As System.Object, _
              ByVal e As System.EventArgs) Handles MyBase.Load
    Dim s2k5 As New Server()
    For Each db As Database In s2k5.Databases ? Loop through the databases
      Databases.Items.Add(db.Name) ? Add database name to the ListBox
    Next
  End Sub
  Private Sub DoBackup_Click(ByVal sender As System.Object, _
                ByVal e As System.EventArgs) Handles DoBackup.Click
    ? Get database name from the ListBox
    Dim db As String = Databases.SelectedItem.ToString()
    Dim dbBck As String = «C:» & db & «.bak»
    Dim bck As New Backup() ? Instantiate a Backup object
    bck.Action = BackupActionType.Database ? Set Action property
    bck.BackupSetName = db & «_BackupSet» ? Set BackupSetName property
    bck.Database = db ? Set Database name property
    bck.DeviceType = DeviceType.File ? Set DeviceType property
    ? Add method adds file to Devices collection
    bck.Devices.Add(dbBck)
    Dim s2k5 As New Server() ? Instantiate a Server object
    bck.SqlBackup(s2k5) ? Invoke Backup object?s SqlBackup method
    Dim rst As New Restore() ? Instantiate a Restore object
    rst.DeviceType = DeviceType.File ? Set DeviceType property
    ? Add method adds file to Devices collection
    rst.Devices.Add(dbBck)
    If rst.SqlVerify(s2k5) Then ? Similar to VERIFY RESTOREONLY
      MessageBox.Show(db & « backup verified»)
    Else
      MessageBox.Show(db & « backup error»)
    End If
  End Sub
End Class