Hi all,
I am trying to incorporate a backup routine of a MS2012 express database within a Vb.NET application. However, I keep getting an 'Index was outside the bounds of the array error ad the dim cMyString trap. Anyone any ideas on where I am going wrong. Using VS 2010. Database is MS SQLExpress2012 Build 11.0.2100
Anyway here is my code:
Private Sub BackItUp()
Try
Dim ConnectionString As String = "Data Source=WDEA_W7\SQLEXPRESS;Initial Catalog= XXX;Integrated Security=SSPI;"
Dim SqlCon As SqlClient.SqlConnection = New SqlClient.SqlConnection(ConnectionString)
SqlCon.Open()
Dim SC As New ServerConnection(SqlCon)
Dim srv As New Server(SC)
'Verify User Instance connection
Dim cMyString As String = "User Instance Server: " & srv.InstanceName.ToString 'INDEX outside the bounds of the array
'Declare a BackupDeviceItem by supplying the backup device file name in the constructor, and the type of device is a file.
Dim bdi As New BackupDeviceItem("C:\Backup.bak", DeviceType.File)
'***Set backup details
Dim bk As New Backup
bk.Devices.Add(bdi)
bk.Action = BackupActionType.Database
bk.BackupSetDescription = "Full Backup_QL"
bk.BackupSetName = "MYBackup"
bk.Database = SqlCon.Database.ToString()
Dim backupdate As New Date(2013, 6, 1)
bk.ExpirationDate = backupdate
bk.LogTruncation = BackupTruncateLogType.Truncate
'Set the Incremental property to False to specify that this is a full database backup.
bk.Incremental = False
'Run SqlBackup to perform the full database backup on the user instance of SQL Server.
bk.SqlBackup(srv)
'Inform the user that the backup has been completed.
MsgBox("Full Backup complete.")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Thanks in advance,
Morke
I am trying to incorporate a backup routine of a MS2012 express database within a Vb.NET application. However, I keep getting an 'Index was outside the bounds of the array error ad the dim cMyString trap. Anyone any ideas on where I am going wrong. Using VS 2010. Database is MS SQLExpress2012 Build 11.0.2100
Anyway here is my code:
Private Sub BackItUp()
Try
Dim ConnectionString As String = "Data Source=WDEA_W7\SQLEXPRESS;Initial Catalog= XXX;Integrated Security=SSPI;"
Dim SqlCon As SqlClient.SqlConnection = New SqlClient.SqlConnection(ConnectionString)
SqlCon.Open()
Dim SC As New ServerConnection(SqlCon)
Dim srv As New Server(SC)
'Verify User Instance connection
Dim cMyString As String = "User Instance Server: " & srv.InstanceName.ToString 'INDEX outside the bounds of the array
'Declare a BackupDeviceItem by supplying the backup device file name in the constructor, and the type of device is a file.
Dim bdi As New BackupDeviceItem("C:\Backup.bak", DeviceType.File)
'***Set backup details
Dim bk As New Backup
bk.Devices.Add(bdi)
bk.Action = BackupActionType.Database
bk.BackupSetDescription = "Full Backup_QL"
bk.BackupSetName = "MYBackup"
bk.Database = SqlCon.Database.ToString()
Dim backupdate As New Date(2013, 6, 1)
bk.ExpirationDate = backupdate
bk.LogTruncation = BackupTruncateLogType.Truncate
'Set the Incremental property to False to specify that this is a full database backup.
bk.Incremental = False
'Run SqlBackup to perform the full database backup on the user instance of SQL Server.
bk.SqlBackup(srv)
'Inform the user that the backup has been completed.
MsgBox("Full Backup complete.")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Thanks in advance,
Morke