Cursor.Current = Cursors.WaitCursor;
try
{
if (txtFileName.Text == "")
{
MessageBox.Show("Please Select Restore File.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
txtFileName.Focus();
return;
}
FileInfo file = new FileInfo(txtFileName.Text);
if (file.Exists)
{
if (MessageBox.Show("Are you sure you restore?", "Back", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
if (file.Extension == ".mbk")
{
}
else
{
FileInfo filebak = new FileInfo(txtFileName.Text);
String Conn = File.ReadAllText("ConnectionString.txt");
SqlConnection _SqlConnection = new SqlConnection(Conn);
_SqlConnection.Open();
//_SqlCommand = new SqlCommand("use master", connect);
//_SqlCommand.ExecuteNonQuery();
_SqlCommand = new SqlCommand("USE master ALTER DATABASE " + "PragatiDB" + " SET SINGLE_USER WITH ROLLBACK IMMEDIATE; ALTER DATABASE " + "PragatiDB" + " SET MULTI_USER;", _SqlConnection);
_SqlCommand.ExecuteNonQuery();
_SqlCommand = new SqlCommand(@"restore database " + "PragatiDB" + " from disk = '" + BackupPath_bak + "\\" + filebak.Name + "' WITH REPLACE", _SqlConnection);
_SqlCommand.ExecuteNonQuery();
_SqlConnection.Close();
//Directory.Delete(BackupPath_bak, true);
}
MessageBox.Show("Database " + "PragatiDB" + " Restored successfully.", "Restoration", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
MessageBox.Show(@"Do not make any endorsement above (or is not in the correct path)", "Restoration", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}