- Làm thế này
Code:
public static void Backup_DataBase(string pathDB, string pathBK, SqlConnection myConnection)
{
try
{
if(myConnection.State != ConnectionState.Open) myConnection.Open();
SqlCommand command = new SqlCommand();
command.Connection = myConnection;
command.CommandText = "BACKUP DATABASE [" + pathDB + "] TO DISK='" + pathBK + "'";
command.ExecuteNonQuery();
}
catch (Exception ex) { MessageBox.Show(ex.Message) ; }
}
public static void Restore_DataBase(string pathReciever, string pathBK, SqlConnection myConnection)
{
try
{
if(myConnection.State != ConnectionState.Open) myConnection.Open();
SqlCommand command = new SqlCommand();
command.Connection = myConnection;
command.CommandText = "Use master; Restore Database [" + pathReciever + "] from disk='" + pathBK + "' WITH REPLACE";
command.ExecuteNonQuery();
}
catch (Exception ex) { MessageBox.Show(ex.Message) }
}