protected void Button1_Click(object sender, EventArgs e)
{
///
///备份方法
///
SqlConnection conn = new SqlConnection("Server=.; Database=aaaa; User ID=sa; Password=sa;");
SqlCommand cmdBK = new SqlCommand();
cmdBK.CommandType = CommandType.Text;
cmdBK.Connection = conn;
//bak为文件名,其他的不用管
cmdBK.CommandText = @"backup database test to disk='D:/bak'with init";
try
{
conn.Open();
cmdBK.ExecuteNonQuery();
MessageBox.Show("Backup successed.");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
conn.Dispose();
}
}