private
void Restore(string filename)
{
try
string command = @
"ALTER DATABASE PSI SET SINGLE_USER with ROLLBACK IMMEDIATE "
+
" USE master "
" RESTORE DATABASE PSI FROM DISK= N'"
+ filename +
"'"
;
//string command = @"RESTORE DATABASE DBName FROM DISK ='" + filename + "' ";
this.Cursor = Cursors.WaitCursor;
SqlCommand ocommand = null;
SqlConnection oconnection = null;
oconnection =
new
SqlConnection(
"Data Source=(local);Initial Catalog=DBName ;user id=sa"
);
if
(oconnection.State != ConnectionState.Open)
oconnection.Open();
ocommand =
SqlCommand(command, oconnection);
ocommand.ExecuteNonQuery();
this.Cursor = Cursors.Default;
MessageBox.Show(
"??????? ??????? ?? ???? ??????? ?? ?? ?????? ????? ??"
}
catch
(Exception ex)
"Error : "
, ex.Message);
string filename = string.
Empty
openFileDialog1.Filter = @
"SQL Backup Files ALL Files (*.*) |*.*| (*.Bak)|*.Bak"
openFileDialog1.FilterIndex = 1;
"SQL Backup Files (*.*)|"
// string DateDay = FarsiLibrary.Utils.PersianDate.Now.ToString().Subs tring(0, 10);
// openFileDialog1.FileName = DateDay.Replace("/", "") + "_" + DateTime.Now.Hour.ToString() + "-" + DateTime.Now.Minute.ToString() + "-" + DateTime.Now.Second.ToString();
(openFileDialog1.ShowDialog() == DialogResult.OK)
filename = openFileDialog1.FileName;
Restore(filename);