كود :
Try
With OpenFileDialog1
.Filter = ("DB Backup File|*.bak;")
.FilterIndex = 4
End With
'Clear the file name
OpenFileDialog1.FileName = ""
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Cursor = Cursors.WaitCursor
Timer1.Enabled = True
SqlConnection.ClearAllPools()
conn.Open()
Dim cb As String = "USE Master ALTER DATABASE lesson SET Single_User WITH Rollback Immediate Restore database lesson FROM disk='" & OpenFileDialog1.FileName & "' WITH REPLACE ALTER DATABASE lesson SET Multi_User "
dim cmd as new SqlCommand(cb)
cmd.Connection = conn
cmd.ExecuteReader()
con.Close()
MessageBox.Show("Successfully performed", "Database Restore", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
وفي حدث التايمر ون كليك ضع الكود التالي
كود :
Cursor = Cursors.Default
Timer1.Enabled = False