Backup sql database error RRS feed

  • Question

  • Hi everyone

    I made a program for backup sql database. when i back up there's an error show like this

    Cannot open backup device 'C:\\aw.bak'. Operating system error 5(Access is denied.).

    BACKUP DATABASE is terminating abnormally.


    what it's means Operation system error 5? it's about on my os?. by d way this is my code

    Public Class Form1
        Dim cmd As SqlCommand
        Dim conn As SqlConnection
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            conn = New SqlConnection("Data Source=RYAN-PC\RYAN;Initial Catalog=trydb;User ID=sa;Password=12345")
        End Sub
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim saveFileDialog1 As New SaveFileDialog()
            Dim mybackup As String
            saveFileDialog1.Filter = "Backup Files (*.bak)|*.bak"
            saveFileDialog1.FilterIndex = 2
            saveFileDialog1.RestoreDirectory = True
            If saveFileDialog1.ShowDialog() = DialogResult.OK Then
                mybackup = Path.GetDirectoryName(saveFileDialog1.FileName) + "\" + Path.GetFileName(saveFileDialog1.FileName)
                Label1.Text = mybackup
                cmd = New SqlCommand(" BACKUP DATABASE [trydb] TO DISK = '" & mybackup & "' ", conn)
                MsgBox("backup success!")
            End If
        End Sub
    End Class

    Saturday, October 8, 2011 3:39 PM


  • By the way problem solved.. I change the log on that i used sql service into the Local System
    • Marked as answer by Mike Feng Monday, October 10, 2011 2:53 AM
    Saturday, October 8, 2011 4:31 PM

All replies