private void Restore(string strfilename)
{
try
{
string command = "ALTER DATABASE alarm SET SINGLE_USER with ROLLBACK IMMEDIATE " +
"use master " +
" RESTORE DATABASE alarm FROM DISK='" + strfilename + "'WITH REPLACE";
this.Cursor = Cursors.WaitCursor;
SqlConnection con = new SqlConnection();
con.ConnectionString = connection;
if (con.State != ConnectionState.Open)
con.Open();
SqlCommand cmd = new SqlCommand(command, con);
cmd.ExecuteNonQuery();
this.Cursor = Cursors.Default;
MessageBox.Show("بازیابی اطلاعات با موفقیت انجام شد");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message );
}
}
private void buttonRestore_Click(object sender, EventArgs e)
{
string strfilename = string.Empty;
openFileDialog1.Filter = @"SQL Backup files files(*.BAK)|*.BAK|All files(*.*)|*.*";
openFileDialog1.Title = "Restore SQL File";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
strfilename = openFileDialog1.FileName;
Restore(strfilename);
}