ghasem deh

ghasem deh

  • NA
  • 258
  • 37.9k

error in restore sql in sql ...

Sep 1 2014 2:03 PM
hi guys ...
 i use this code for restore :
 
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 = new SqlCommand(command, oconnection);
ocommand.ExecuteNonQuery();
this.Cursor = Cursors.Default;
MessageBox.Show("??????? ??????? ?? ???? ??????? ?? ?? ?????? ????? ??");
}
catch (Exception ex)
{
MessageBox.Show("Error : ", ex.Message);
}
}
 and button restore :
 
string filename = string.Empty;
openFileDialog1.Filter = @"SQL Backup Files ALL Files (*.*) |*.*| (*.Bak)|*.Bak";
openFileDialog1.FilterIndex = 1;
openFileDialog1.Filter = @"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();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
filename = openFileDialog1.FileName;
Restore(filename);
}
 
 
  but error : Pic
 

Answers (1)