راهنماییم کنین لطفا.الان با این کد بکاپم درست شد.
string command = @"BACKUP DATABASE [" + Application.StartupPath + "\\accounting.mdf] TO DISK = N'" + strFileName + "' WITH NOFORMAT, NOINIT, NAME = N'accounting-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10";
this.Cursor = Cursors.WaitCursor;
SqlCommand oCommand = null;
SqlConnection oConnection = null;
string scnn = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\accounting.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
oConnection = new SqlConnection(scnn);
if (oConnection.State != ConnectionState.Open)
oConnection.Open();
oCommand = new SqlCommand(command, oConnection);
oCommand.ExecuteNonQuery();
this.Cursor = Cursors.Default;
oConnection.Close();
ولی ریستورم یا این کدی که براتون می زارم ارور می ده
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.\\sqlexpress;Initial catalog=master;Integrated Security=true";
//con.ConnectionString = "Data Source=.;Initial catalog=master;Integrated Security=true";
SqlCommand cmd = new SqlCommand();
con.Open();
string query = "USE master RESTORE DATABASE [" + Application.StartupPath + "\\accounting.mdf] FROM DISK ='" + strFileName + "'WITH RECOVERY, REPLACE";
cmd.CommandText = query;
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();