private void btRestore_Click(object sender, Ev entArgs e)
{
try
{
string path = "D:\\backupUITGPP.bak";
string sqlRestore = "Use master Restore Database [UITGPP] from disk='" + path + "'";
SqlConnection con = new SqlConnection("Data Source=ACUMEN-PC\\SQLEXPRESS;Initial Catalog=Ketnoimoi;Integrat ed Security=True");
con.Open();
SqlCommand cmd = new SqlCommand(sqlRestore, con);
cmd.ExecuteNonQuer y();
con.Close();
MessageBox.Show("Database da duoc restore ");
}
catch (SqlException ex)
{
MessageBox.Show(ex .Message, "Restore Database");
return;
}
catch (Exception ex)
{
}
}
Backup:
private void btBackUp_Click(object sender, Eve ntArgs e)
{
try
{
string sqlBackup = "BACKUP DATABASE [UITGPP] TO DISK='D:\\backupUITGPP.bak'";
SqlConnection con =new SqlConnection("Data Source=ACUMEN-PC\\SQLEXPRESS;Initial Catalog=UITGPP;IntegratedSecurity=True");
con.Open();
SqlCommand cmd = new SqlCommand(sqlBackup, con);
cmd.ExecuteNonQuer y();
con.Close();
MessageBox.Show("Đã backup cơ sở dữ liệu");
}
catch (SqlException ex)
{
MessageBox.Show(ex .Message, "Backup Database");
return;
}
catch (Exception ex)
{
}
}
{
try
{
string path = "D:\\backupUITGPP.bak";
string sqlRestore = "Use master Restore Database [UITGPP] from disk='" + path + "'";
SqlConnection con = new SqlConnection("Data Source=ACUMEN-PC\\SQLEXPRESS;Initial Catalog=Ketnoimoi;Integrat ed Security=True");
con.Open();
SqlCommand cmd = new SqlCommand(sqlRestore, con);
cmd.ExecuteNonQuer y();
con.Close();
MessageBox.Show("Database da duoc restore ");
}
catch (SqlException ex)
{
MessageBox.Show(ex .Message, "Restore Database");
return;
}
catch (Exception ex)
{
}
}
Backup:
private void btBackUp_Click(object sender, Eve ntArgs e)
{
try
{
string sqlBackup = "BACKUP DATABASE [UITGPP] TO DISK='D:\\backupUITGPP.bak'";
SqlConnection con =new SqlConnection("Data Source=ACUMEN-PC\\SQLEXPRESS;Initial Catalog=UITGPP;IntegratedSecurity=True");
con.Open();
SqlCommand cmd = new SqlCommand(sqlBackup, con);
cmd.ExecuteNonQuer y();
con.Close();
MessageBox.Show("Đã backup cơ sở dữ liệu");
}
catch (SqlException ex)
{
MessageBox.Show(ex .Message, "Backup Database");
return;
}
catch (Exception ex)
{
}
}
Nguồn: congdongcviet.com
Không có nhận xét nào:
Đăng nhận xét