When we are developing a Web site, in the admin background, the administrator usually makes a regular backup of the database (and, of course, the SQL Server can be automatically backed up regularly, but I'm talking about backup in asp.net), and the backup code is simple:
Here is an event I write under the backup button when I do a website backstage:
protected void Button1_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 (".. /.. /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 server path: + nepath+" click Download to local! ";
Hyperlink1.navigateurl = ".. /.. /databack/"+newname;
Hyperlink1.visible = true;
}
catch (Exception ex)
... {
String EXM = ex. message;
Label1.Text = "BACKUP Database error, this file may not exist!" ";
Label1.visible = true;
}
Finally
... {
Cmd. Dispose ();
cn. Close ();
cn. Dispose ();
}
Of course, the most important thing is this:
BACKUP DATABASE webjake to DISK = ' The path you want to save '