I've been struggling with this for a few days now, so I guess it's time to ask for help. I'm working on a VB Express 2005 Single form windows application that uses a SQL Express 2005 two table data base. I can read and write to the database with no problems. I just can't back it up. I haven't tried restores yet. I created the database in SQL Server Management Studio Express and then connected to it from the VB Express application.
My.Settings.UsersConnectionString is
Data Source=.\sqlexpress;AttachDbFilename="C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Users.mdf";Integrated Security=True;User Instance=True
I used the following code to establish a connection to the server that is the userinstance
Dim SqlConnection As SqlClient.SqlConnection = New SqlClient.SqlConnection(My.Settings.UsersConnectionString)
Dim ServerConnection As ServerConnection = New Microsoft.SqlServer.Management.Common.ServerConnection(SqlConnection)
Dim srv As Server = New Server(ServerConnection)
I am able to confirm the connection to the UserInstance via a message box that displays the instance name
MsgBox(srv.InstanceName.ToString)
Then this code follows:
Dim db As Database
db = srv.Databases(
"USERS")
Dim bk As New Backup
'Specify the type of backup, the description, the name, and the database to be backed up.
bk.Action = BackupActionType.Database
bk.BackupSetDescription =
"Full backup of Users"
bk.BackupSetName =
"Users Backup"
bk.Database =
"USERS"
'Declare a BackupDeviceItem by supplying the backup device file name in the constructor, and the type of device is a file.
Dim bdi As BackupDeviceItem
bdi =
New BackupDeviceItem(AppDir & "Test_Full_Backup1.bak", DeviceType.File)
'Add the device to the Backup object.
bk.Devices.Add(bdi)
bk.Initialize =
True
'Set the Incremental property to False to specify that this is a full database backup.
bk.Incremental =
False
'Set the expiration date.
Dim backupdate As New Date
backupdate =
New Date(2008, 10, 5)
bk.ExpirationDate = backupdate
'Specify that the log must be truncated after the backup is complete.
bk.LogTruncation = BackupTruncateLogType.Truncate
'Run SqlBackup to perform the full database backup on the instance of SQL Server.
bk.SqlBackup(srv)
'Inform the user that the backup has been completed.
MsgBox(
&qu
View Complete Post