views:

22

answers:

0
Dim sqlDataAdapter As SqlDataAdapter
Dim sqlCmd As SqlCommand
Dim sqlCon As SqlConnection
Dim _result As Integer
Dim filePath As String = Application.StartupPath & "\BACKUP\ClinicBackup.bak"
Dim folderPath As String = Application.StartupPath & "\BACKUP"

Private Sub FullBackUp()

    Try
        sqlCmd = New SqlCommand()
        sqlCmd.Connection = sqlCon
        sqlCmd.CommandType = CommandType.StoredProcedure
        sqlCmd.CommandText = "prcBackUpFullData"

        'Add Tenant Details
        sqlCmd.Parameters.AddWithValue("@DatabaseName", "CLINIC")
        sqlCmd.Parameters.AddWithValue("@path", filePath)

        'open sqlcon
        sqlCon.Open()
        'Perfoming the full back up
        Me.LabMsg.Text = "Wait while Dentist Tower is performing the full Clinic back up......"
        _result = sqlCmd.ExecuteNonQuery()

        If _result = -1 Then
            Me.LabMsg.Text = "The Dentist Tower Full back up performed successfully."
            MessageBox.Show("The Clinic database has been back up successfully. ", "Back Up ", MessageBoxButtons.OK, MessageBoxIcon.Information)
            btnBrowse.Enabled = True
            Me.LabMsg.Text = "Done."
        End If
    Catch ex As Exception
        Me.LabMsg.Text = "Unable to perform the hostel back up."
        MessageBox.Show(ex.Message.ToString, "Back up", MessageBoxButtons.OK, MessageBoxIcon.Error)
        MessageBox.Show("Unable to perform the Dentist Tower back up. Close the form and try it again." + vbCrLf + "If the problem persists, please contact the vendor.", "Back up ", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Finally
        sqlCon.Close()
        sqlCmd = Nothing
    End Try

End Sub

Private Sub DifferentialBackUp()

    Try
        sqlCmd = New SqlCommand()
        sqlCmd.Connection = sqlCon
        sqlCmd.CommandType = CommandType.StoredProcedure
        sqlCmd.CommandText = "prcBackUpDiffData"

        'Add Tenant Details
        sqlCmd.Parameters.AddWithValue("@DatabaseName", "CLINIC")
        sqlCmd.Parameters.AddWithValue("@path", filePath)

        'open sqlcon
        sqlCon.Open()
        'Perfoming the differential back up
        Me.LabMsg.Text = "Wait while Dentist Tower is performing the Hostel differential back up......"
        _result = sqlCmd.ExecuteNonQuery()

        If _result = -1 Then
            Me.LabMsg.Text = "The Clinic Differential back up performed successfully."
            MessageBox.Show("The Dentist Tower database has been back up successfully. ", "Back Up", MessageBoxButtons.OK, MessageBoxIcon.Information)
            btnBrowse.Enabled = True
            Me.LabMsg.Text = "Done."
        End If
    Catch ex As Exception
        Me.LabMsg.Text = "Unable to perform the hostel back up."
        MessageBox.Show(ex.Message.ToString, "Back Up", MessageBoxButtons.OK, MessageBoxIcon.Error)
        MessageBox.Show("Unable to perform the Clinic back up. Close the form and try it again." + vbCrLf + "If the problem persists, please contact the vendor.", "Back up ", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Finally
        sqlCon.Close()
        sqlCmd = Nothing
    End Try

End Sub

but the code does not work

this is the message that I get when I try to buckup my database after executing my vb codes

Blockquote Cannot open detabase divice.....Operating system error 5(Access is denied.).

BACKUP DABASE is terminating abnormally.

Blockquote I want a help to solve this problem