資源簡介
本模塊主要實現了備份數據庫、還原數據庫功能。在對數據庫進行操作前,首先需要選擇服務器,及輸入相應的用戶名和密碼,進行登錄,然后才能對數據庫進行操作。單擊“備份數據庫”按鈕,打開“備份本地數據庫”窗口,如圖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個文件信息
評論
共有 條評論