I try to create a Sub for a SQL Dabase backup by code using this code:
But I receive this error:
Incorrect syntax near '-'.
Unclosed quotation mark after the character string ',SKIP, STATS = 10'.
Can you help me?
VB.NET:
Private Sub btnBackup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBackup.Click
Dim sBackup As String = "BACKUP DATABASE " & Me.txtBase.Text & _
" TO DISK = N'" & Me.txtBackup.Text & _
"' WITH NOFORMAT, NOINIT, NAME =N'" & Me.txtBase.Text & _
"' -Full Database Backup',SKIP, STATS = 10"
Dim csb As New SqlConnectionStringBuilder
csb.DataSource = Me.txtServidor.Text
csb.InitialCatalog = Me.txtBase.Text
csb.IntegratedSecurity = True
Using con As New SqlConnection(csb.ConnectionString)
Try
con.Open()
Dim cmdBackUp As New SqlCommand(sBackup, con)
cmdBackUp.ExecuteNonQuery()
MessageBox.Show("Backup Completo", "Backup Base de Datos", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error al copiar la base de datos", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Using
End Sub
But I receive this error:
Incorrect syntax near '-'.
Unclosed quotation mark after the character string ',SKIP, STATS = 10'.
Can you help me?