資源簡介
C#將SQL Server備份bak文件恢復

代碼片段和文件信息
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;
using?System.Diagnostics;
namespace?resume
{
????public?partial?class?ComeBack?:?Form
????{
????????public?ComeBack()
????????{
????????????InitializeComponent();
????????}
????????private?void?btnRevertPath_Click(object?sender?EventArgs?e)
????????{
????????????OpenFileDialog?ofd?=?new?OpenFileDialog();
????????????ofd.InitialDirectory?=?Application.StartupPath?+?“\\“;
????????????ofd.Filter?=?“備份文件(*.bak)|*.bak“;
????????????if?(ofd.ShowDialog()?==?DialogResult.OK)
????????????{
????????????????this.txtRevertPath.Text?=?ofd.FileName;
????????????????this.btnRevert.Enabled?=?true;
????????????}
????????}
????????private?void?btnRevert_Click(object?sender?EventArgs?e)
????????{
????????????string?connStr?=?“Data?Source=.\\SQLEXPRESS;Initial?Catalog=Master;user?id=sa;Pwd=123“;
????????????SqlConnection?con?=?new?SqlConnection(connStr);
????????????try
????????????{
????????????????con.Open();
????????????????string?sql?=?““;
????????????????sql?=?“use?Master“;
????????????????SqlCommand?com?=?new?SqlCommand(sql?con);
????????????????com.ExecuteNonQuery();
????????????????sql?=?“drop?database?GPRS“;
????????????????com?=?new?SqlCommand(sql?con);
????????????????com.ExecuteNonQuery();
????????????????sql?=?string.Format(“use?master?restore?database?{0}?from?disk?=?‘{1}‘“?“GPRS“?txtRevertPath.Text);
????????????????com?=?new?SqlCommand(sql?con);
????????????????com.ExecuteNonQuery();
????????????????DialogResult?result?=?MessageBox.Show(“數據庫恢復成功!“?“提示“?MessageBoxButtons.OK?MessageBoxIcon.Information);
????????????????if?(result?==?DialogResult.Yes)
????????????????{
????????????????????Process.Start(Application.StartupPath?+?“\\Hotel.exe“);
????????????????????Application.Exit();
????????????????}
????????????}
????????????catch?(Exception?ex)
????????????{
????????????????MessageBox.Show(ex.Message);
????????????}
????????????finally
????????????{
????????????????con.Close();
????????????}???????????
????????}
????????private?void?grbRevert_Enter(object?sender?EventArgs?e)
????????{
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????20480??2010-06-27?16:23??resume\resume\bin\Debug\resume.exe
?????文件??????44544??2010-06-27?16:23??resume\resume\bin\Debug\resume.pdb
?????文件???????5632??2005-11-11?22:25??resume\resume\bin\Debug\resume.vshost.exe
????..A.SH.?????????9??2010-04-21?19:51??resume\resume\bin\Debug\_desktop.ini
????..A.SH.?????????9??2010-04-21?19:51??resume\resume\bin\_desktop.ini
?????文件???????2357??2010-06-27?16:23??resume\resume\ComeBack.cs
?????文件???????4767??2010-06-27?16:07??resume\resume\ComeBack.Designer.cs
?????文件???????5814??2010-06-27?16:07??resume\resume\ComeBack.resx
????..A.SH.?????????9??2010-04-21?19:51??resume\resume\obj\Debug\Refactor\_desktop.ini
?????文件????????180??2010-06-27?16:07??resume\resume\obj\Debug\resume.ComeBack.resources
?????文件????????845??2010-06-27?16:07??resume\resume\obj\Debug\resume.csproj.GenerateResource.Cache
?????文件??????20480??2010-06-27?16:23??resume\resume\obj\Debug\resume.exe
?????文件??????44544??2010-06-27?16:23??resume\resume\obj\Debug\resume.pdb
?????文件????????180??2008-10-15?20:20??resume\resume\obj\Debug\resume.Properties.Resources.resources
????..A.SH.?????????9??2010-04-21?19:51??resume\resume\obj\Debug\TempPE\_desktop.ini
????..A.SH.?????????9??2010-04-21?19:51??resume\resume\obj\Debug\_desktop.ini
?????文件????????264??2010-06-27?16:25??resume\resume\obj\resume.csproj.FileList.txt
?????文件????????688??2010-01-21?16:49??resume\resume\obj\resume.csproj.FileListAbsolute.txt
????..A.SH.?????????9??2010-04-21?19:51??resume\resume\obj\_desktop.ini
?????文件????????468??2008-10-15?20:19??resume\resume\Program.cs
?????文件???????1184??2008-10-15?20:18??resume\resume\Properties\AssemblyInfo.cs
?????文件???????2866??2008-10-15?20:18??resume\resume\Properties\Resources.Designer.cs
?????文件???????5612??2008-10-15?20:18??resume\resume\Properties\Resources.resx
?????文件???????1089??2008-10-15?20:18??resume\resume\Properties\Settings.Designer.cs
?????文件????????249??2008-10-15?20:18??resume\resume\Properties\Settings.settings
????..A.SH.?????????9??2010-04-21?19:51??resume\resume\Properties\_desktop.ini
?????文件???????3234??2008-10-15?20:20??resume\resume\resume.csproj
????..A.SH.?????????9??2010-04-21?19:51??resume\resume\_desktop.ini
?????文件????????907??2008-10-15?20:18??resume\resume.sln
????..A..H.?????14336??2010-06-27?17:42??resume\resume.suo
............此處省略13個文件信息
- 上一篇:用c#寫的多線程求PI
- 下一篇:利用C#語言開發K-Means聚類算法
評論
共有 條評論