c#中数据库的备份和恢复

该博客介绍了如何在C#中实现数据库的备份和恢复功能。通过点击菜单触发事件,调用BackUpAndReinstate组件中的BackUp和Reinstate类方法,进行数据的备份和恢复操作。在备份过程中,创建了数据库设备并执行备份命令;在恢复过程中,使用RESTORE DATABASE命令替换现有数据库。
摘要由CSDN通过智能技术生成

//数据备份菜单点击事件
   private void mnuBackUp_Click(object sender, System.EventArgs e)
   {
    frmBackUp back=new frmBackUp(frmBackUp.SetType.BackUp);
    back.Show();
    //调用dll
    BackUpAndReinstate.BackUp backup=new BackUpAndReinstate.BackUp(Application.StartupPath+"//BackUp//TeachingBusiness.bak");
    string message=backup.DataBaseBackUp();
    MessageBox.Show(message,"消息",MessageBoxButtons.OK,MessageBoxIcon.Information);
    back.Close();
   }

   //数据恢复菜单点击事件
   private void mnuReinstate_Click(object sender, System.EventArgs e)
   {
    frmBackUp back=new frmBackUp(frmBackUp.SetType.Reinstate);
    back.Show();
    //调用dll
    BackUpAndReinstate.Reinstate reinstate=new BackUpAndReinstate.Reinstate();
    string message=reinstate.DataBaseReinstate();
    MessageBox.Show(message,"消息",MessageBoxButtons.OK,MessageBoxIcon.Information);
    back.Close();
   }

frmBackUp窗体代码:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace 教务系统
{
/// <summary>
/// frmBackUp 的摘要说明。
/// </summary>
public class frmBackUp : System.Windows.Forms.Form
{
   private System.Windows.Forms.Label label1;
   private System.Windows.Forms.PictureBox pictureBox1;
   private System.Windows.Forms.Timer timer1;
   private System.ComponentModel.IContainer components;

   public enum SetType
   {
    BackUp,
    Reinstate
   }
   private int type=0;
   public frmBackUp(SetType settype)
   {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent();
    this.type=(int)settype;
    //
    //
   }

   /// <summary>
   /// 清理所有正在使用的资源。
   /// </summary>
   protected override void Dispose( bool disposing )
   {
    if( disposing )
    {
     if(components != null)
     {
      components.Dispose();
     }
    }
    base.Dispose( disposing );
   }

   #region Windows 窗体设计器生成的代码
   /// <summary>
   /// 设计器支持所需的方法 - 不要使用代码编辑器修改
   /// 此方法的内容。
   /// </summary>
   private void InitializeComponent()
   {
    this.compo

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值