Backing up the restore SQL Server database in asp.net

Source: Internet
Author: User
Tags backup

In the Web, security is mainly embodied in two aspects: one is the program security, that is, to prevent the Web page in the insertion of malicious code, the other is database security, which we can often back up the database to achieve.

In the article, I'll show you how to back up and restore a database in a Web page.

In fact, backup and recovery databases are backed up by SQL Server-supplied SQL statements.

Backup: Use Master;backup database @name to disk= @path;

Recovery: Use Master;restore database @name the @path from disk=;

The above is a parameterized SQL statement that can be dynamically assigned to a parameter when the program executes.

Code:

<%@ Page language= "C # autoeventwireup=" true "codefile=" DatabaseAction.aspx.cs "inherits=" Databaseaction "%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
<title> Untitled Page    </title>
<body>
<form id= "Form1" runat= "Server"
<div>
<table border= "0" width= "100%"
<tr><td colspan= "2" > Database restore and Backup </td></tr>
<tr ><td> Please select database </td><td>
<asp:dropdownlist id= "ddldatabaselist" runat= "Server"
& Lt;/asp:dropdownlist></td></tr>
<tr><td>
Database file name </td><td>
& Lt;asp:textbox id= "Txtdbfilename" runat= "Server" ></ASP:TEXTBOX></TD></TR>
<tr>< Td>
Action Options </td> <td>
<asp:radiobutton id= "rbbackup" runat= "Server" checked= "True" groupname= "action" text= "Backup"/>
<asp:radiobutton id= "Rbrestore" runat= "Server" groupname= "action" text= "restore"/></TD></TR>
<tr><td>
Operation </td><td>
<asp:button id= "Btnok" runat= "Server" onclick= "btnOK_ Click text= "Execute"/></td></tr>
</table>
</div>
</form>
</body& Gt

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.