• 大小: 1.16MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-11-12
  • 语言: C#
  • 标签: SQL  数据库  

资源简介

本模块主要实现了备份数据库、还原数据库功能。在对数据库进行操作前,首先需要选择服务器,及输入相应的用户名和密码,进行登录,然后才能对数据库进行操作。单击“备份数据库”按钮,打开“备份本地数据库”窗口,如图1.2所示。输入备份文件名,选择要备份的数据库,然后再选择保存备份文件的路径,单击“确定”按钮对数据库进行备份。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace SQL_Distill
{
    public partial class frmAppend : Form
    {
        public frmAppend()
        {
            InitializeComponent();
        }
        public string strserver = ““;
        public string struser = ““;
        public string strpwd = ““;
        private void button3_Click(object sender EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = openFileDialog1.FileName;
            }
        }

        private void button2_Click(object sender EventArgs e)
        {
            if (textBox1.Text.Trim() == ““)
            {
                MessageBox.Show(“注意:信息不完整!“ “警告“ MessageBoxButtons.OK MessageBoxIcon.Exclamation);
            }
            else
            {
                using (SqlConnection con = new SqlConnection(“server=.;pwd=“ + strpwd + “;uid=“ + struser + “;database=master“))
                {
                    try
                    {
                        string[] getInfo = new string[2];
                        string mdfpath = textBox1.Text.Trim();//mdf路径
                        string DataName = mdfpath.Substring(mdfpath.LastIndexOf(“\\“)+1mdfpath.Length-mdfpath.LastIndexOf(“\\“)-1);
                        DataName = DataName.Remove(DataName.LastIndexOf(“_“));
                        string logName =mdfpath.Remove(mdfpath.LastIndexOf(“\\“))+“\\“+DataName + “_log.ldf“;
                        SqlCommand cmd = new SqlCommand();
                        con.Open();
                        cmd.Connection = con;
                        StringBuilder sb = new StringBuilder();
                        sb.Append(“sp_attach_db @dbname=‘“ + DataName + “‘“);
                        sb.Append(“@filename1=‘“ + mdfpath + “‘“);
                        if (System.IO.File.Exists(logName))
                        {
                            sb.Append(“@filename2=‘“ + logName + “‘“);
                        }
                        else
                        {
                            MessageBox.Show(“注意:缺少必备的log文件!“ “警告“ MessageBoxButtons.OK MessageBoxIcon.Exclamation);
                        }
                        cmd.CommandText = sb.ToString();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        MessageBox.Show(“提示:附加成功!“ “提示“ MessageBoxButtons.OK MessageBoxIcon.Exclamation);
                        getInfo[0] = mdfpath.Substring(mdfpath.LastIndexOf(“\\“) + 1 mdfpath.Length - mdfpath.LastIndexOf(“\\“) - 1);
                        getInfo[1] = mdfpath;
                        ListViewItem lvi =

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       5632  2005-12-08 14:51  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\bin\Debug\SQL-Distill.vshost.exe

     文件       3437  2008-07-29 16:59  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\frmAppend.cs

     文件       7265  2008-07-29 15:35  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\frmAppend.Designer.cs

     文件       6017  2008-07-29 15:35  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\frmAppend.resx

     文件       3608  2008-08-18 10:39  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\frmBackup.cs

     文件       7022  2008-07-29 15:34  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\frmBackup.Designer.cs

     文件       6022  2008-07-29 15:34  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\frmBackup.resx

     文件       6765  2008-07-31 09:16  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\frmDataExport.cs

     文件       7564  2008-07-30 08:28  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\frmDataExport.Designer.cs

     文件       6017  2008-07-30 08:28  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\frmDataExport.resx

     文件      13851  2008-08-21 09:25  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\frmMain.cs

     文件      22806  2008-08-04 13:39  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\frmMain.Designer.cs

     文件      15513  2008-08-04 13:39  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\frmMain.resx

     文件       7001  2008-08-04 12:59  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\frmOutData.cs

     文件       7601  2008-07-30 14:32  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\frmOutData.Designer.cs

     文件       6017  2008-07-30 14:32  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\frmOutData.resx

     文件       3305  2008-07-31 08:44  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\frmRevert.cs

     文件       6667  2008-07-29 13:20  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\frmRevert.Designer.cs

     文件       6017  2008-07-29 13:20  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\frmRevert.resx

     文件     409600  2013-03-05 09:14  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\obj\Debug\Interop.Microsoft.Office.Core.dll

     文件    1273856  2013-03-05 09:14  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\obj\Debug\Interop.Microsoft.Office.Interop.Excel.dll

     文件     778240  2013-03-05 09:14  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\obj\Debug\Interop.Microsoft.Office.Interop.Word.dll

     文件     950272  2013-03-05 09:14  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\obj\Debug\Interop.SQLDMO.dll

     文件      57344  2013-03-05 09:14  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\obj\Debug\Interop.VBIDE.dll

     文件       1159  2013-03-05 09:14  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\obj\Debug\SQL-Distill.csproj.GenerateResource.Cache

     文件        873  2013-03-05 09:14  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\obj\Debug\SQL-Distill.csproj.ResolveComReference.cache

     文件        180  2013-03-05 09:14  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\obj\Debug\SQL_Distill.frmAppend.resources

     文件        180  2013-03-05 09:14  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\obj\Debug\SQL_Distill.frmBackup.resources

     文件        180  2013-03-05 09:14  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\obj\Debug\SQL_Distill.frmDataExport.resources

     文件       7079  2013-03-05 09:14  SQL数据备份恢复程序\SQL-Distill\Backup\SQL-Distill\obj\Debug\SQL_Distill.frmMain.resources

............此处省略96个文件信息

评论

共有 条评论