The following is an event that I wrote under the "backup" button when I made a website background:
Protected void button#click (object sender, EventArgs e)
...{
String newname = "WebJake" + DateTime. now. year. toString () + DateTime. now. month. toString () + DateTime. now. day. toString () + DateTime. now. hour. toString () + ". bak ";
SqlConnection cn = DB. createCon ();
String nepath = Server. MapPath ("http://www.cnblogs.com/DataBack/") + newname;
String SQL = "BACKUP DATABASE WebJake to DISK = '" + nepath + "'";
SqlCommand cmd = new SqlCommand (SQL, cn );
Try
...{
Cn. Open ();
Cmd. ExecuteNonQuery ();
HyperLink1.Text = "successfully backed up to the server path:" + nepath + "click to download to local! ";
HyperLink1.NavigateUrl = "http://www.cnblogs.com/DataBack/" + newname;
HyperLink1.Visible = true;
}
Catch (Exception ex)
...{
String exm = ex. Message;
Label1.Text = "An error occurred while backing up the database. This file may not exist! ";
Label1.Visible = true;
}
Finally
...{
Cmd. Dispose ();
Cn. Close ();
Cn. Dispose ();
}
Of course, the most important thing is this sentence:
Backup database WebJake to DISK = 'path to save'