Backup in ASP. NET

Source: Internet
Author: User

Backup in ASP. NET

When developing a website, in the management background, the Administrator usually regularly backs up the database (of course, The sqlserver server can also perform regular automatic backup, but here I am talking about ASP. NET), the backup code is very simple:

The following is an event that I wrote under the "backup" button when I made a website background:

 
 
  1. Protectedvoidbutton#click (objectsender, EventArgse)
  2. ...{
  3. Stringnewname="WebJake"+ DateTime. Now. Year. ToString () +
    DateTime. Now. Month. ToString () + DateTime. Now. Day. ToString () +
    DateTime. Now. Hour. ToString () + ". bak ";
  4. SqlConnectioncn=DB. CreateCon ();
  5. Stringnepath=Server. MapPath (".../../DataBack/") + newname;
  6. Stringsql="BACKUPDATABASEWebJaketoDISK = '"+ Nepath + "'";
  7. SqlCommandcmd=NewSqlCommand(SQL, cn );
  8. Try
  9. ...{
  10. Cn. Open ();
  11. Cmd. ExecuteNonQuery ();
  12. HyperLink1.Text="The backup has been successfully backed up to the server path :"+ Nepath + "click to download to local! ";
  13. HyperLink1.NavigateUrl=".../DataBack /"+ Newname;
  14. HyperLink1.Visible=True;
  15. }
  16. Catch (Exceptionex)
  17. ...{
  18. Stringexm= Ex. Message;
  19. Label1.Text="An error occurred while backing up the database. This file may not exist! ";
  20. Label1.Visible=True;
  21. }
  22. Finally
  23. ...{
  24. Cmd. Dispose ();
  25. Cn. Close ();
  26. Cn. Dispose ();
  27. }
  28. }

Of course, the most important thing is this sentence:

Backup database WebJake to DISK = 'path you want to save '. The above describes the BACKUP in ASP. NET.

  1. Analysis on PageBase and MasterPage of ASP. NET
  2. XML Web Service Method of ASP. NET
  3. Detailed description of ASP. NET environment deployment
  4. Implement ASP. NET globalization
  5. Solve the Problem of ASP. net ajax script errors

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.