hi guys ...
i use this code for restore :
private void Restore(string filename)Java
{
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);
}
} string filename = string.Empty;Bash
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

ghasem deh171 pointsPosted Sep 2, 2014, 6:26 AM EDT
private void Restore(string strFileName) { // try // { try { if (strFileName != string.Empty) { string command =" WITH REPLACE"; var oConnection = new SqlConnection("server=localhost;Integrated security=true;database=PSI"); if (oConnection.State != ConnectionState.Open) oConnection.Open(); var oCommand = new SqlCommand(command, oConnection); oCommand.ExecuteNonQuery(); MessageBox.Show(". ??????? ??????? ?? ???? ??????? ?? ?????? ????? ??"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } // catch (Exception ex) // { // MessageBox.Show("Error : ", ex.Message); // }