I want to make a backup copy of my SQL Server localdb database. I tried with this code:
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim Sfd As New SaveFileDialog() With {
.Filter = "Backup file | *.bak",
.FileName = ""
}
If Sfd.ShowDialog = System.Windows.Forms.DialogResult.OK Then
Cursor = Cursors.WaitCursor
Dim dbname As String = "RestoDB.mdf"
Dim sql As String = "Backup database [" + System.Windows.Forms.Application.StartupPath + "\RestoDB.mdf] To DISK = '{Sfd.Filename}'"
Dim cmd As New SqlCommand(sql, con)
cmd.ExecuteNonQuery()
MsgBox("Backup complete")
Cursor = Cursors.Default
End If
End Sub
I get an error telling me
does not exist. Make sure that the name is entered correctly.
This is the connection string:
Private con As New SqlClient.SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\CHAKER\Documents\RestoDB.mdf;Integrated Security=True;Connect Timeout=30")