c#写的sql Server数据库自动备份程序

本文介绍了使用C#语言编写的SQL Server 2005 Express数据库自动备份程序,旨在提供一种在Windows XP环境下确保数据库安全的方法。程序能够定期执行备份任务,对数据库进行保护。
摘要由CSDN通过智能技术生成

这几天写了一个xp下安装sql Server 2005 express版本的数据库自动备份程序,大家看看若是有觉得不合理的地方欢迎指正



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using Microsoft.Win32;
using System.Diagnostics;


namespace CPU卡表数据库备份程序
{
    public partial class Config : Form
    {
        public Config()
        {
            InitializeComponent();
        }


        private void Config_Load(object sender, EventArgs e)
        {
            //this.Cb_Hour.SelectedIndex = 0;
            //this.Cb_Minute.SelectedIndex = 0;
            string Dir_Source = GetValue("Dir");
            this.Txt_DirSource.Text = Dir_Source;
            string Hour = GetValue("Hour").Trim();
            string Minute = GetValue("Minute").Trim();
            this.Cb_Hour.Text = Hour;
            this.Cb_Minute.Text = Minute;
            string AutoRun = GetValue("AutoRun");
            if (AutoRun.Trim() == "false")
            {
                this.CheckBox_AutoRun.Checked = false;
            }
            else
            {
                this.CheckBox_AutoRun.Checked = true;
            }
        }


        private void Txt_DirSource_MouseClick(object sender, MouseEventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.Description = "请选择备份路径";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.Txt_DirSource.Text = dialog.SelectedPath;
            }
            else
            {
                return;
            }
        }


        private void Btn_SetDir_Click(object sender, EventArgs e)
        {
            //首先判断目录是否存在
            string Dir_Source = this.Txt_DirSource.Text.Trim();
            if (Dir_Source == "" || Directory.Exists(Dir_Source) == false)
            {
                MessageBox.Show("备份目录设置有误,请查证", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                SetValue("Dir", Dir_Source);
                MessageBox.Show("备份目录设置为"+Dir_Source,"提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                return;
 
            }
            
        }
        /// <summary>
        /// 设置程序开机启动
        /// 或取消开机启动
        /// </summary>
        /// <param name="started">设置开机启动,或者取消开机启动</param>
        /// <param name="exeName">注册表中程序的名字</param>
        /// <param name="path">开机启动的程序路径</param>
        /// <returns>开启或则停用是否成功</returns>
        public static bool runWhenStart(bool started, string exeName, string path)
        {
            RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);//打开注册表子项
            if (key == null)//如果该项不存在的话,则创建该子项
            {
                key = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
            }
            if (started == true)
            {
                try
                {
                    key.SetValue(exeName, path);//设置为开机启动
                    k
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值