Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem using Backup Database

Author  Topic 

jotae
Starting Member

3 Posts

Posted - 2009-09-13 : 21:17:32
I try to create a Sub for a SQL Dabase backup by code using this code:

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?

Jorge E. Villamizar

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-09-13 : 23:30:26
Show us what sBackup contains. I have a feeling you are missing a single quote somewhere in there.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -