欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

c#中數(shù)據(jù)庫(kù)的備份和恢復(fù)

系統(tǒng) 2134 0

//數(shù)據(jù)備份菜單點(diǎn)擊事件
?? private void mnuBackUp_Click(object sender, System.EventArgs e)
?? {
??? frmBackUp back=new frmBackUp(frmBackUp.SetType.BackUp);
??? back.Show();
??? //調(diào)用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();
?? }

?? //數(shù)據(jù)恢復(fù)菜單點(diǎn)擊事件
?? private void mnuReinstate_Click(object sender, System.EventArgs e)
?? {
??? frmBackUp back=new frmBackUp(frmBackUp.SetType.Reinstate);
??? back.Show();
??? //調(diào)用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 教務(wù)系統(tǒng)
{
/// <summary>
/// frmBackUp 的摘要說(shuō)明。
/// </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 窗體設(shè)計(jì)器支持所必需的
??? //
??? 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 窗體設(shè)計(jì)器生成的代碼
?? /// <summary>
?? /// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改
?? /// 此方法的內(nèi)容。
?? /// </summary>
?? private void InitializeComponent()
?? {
??? this.components = new System.ComponentModel.Container();
??? System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmBackUp));
??? this.label1 = new System.Windows.Forms.Label();
??? this.pictureBox1 = new System.Windows.Forms.PictureBox();
??? this.timer1 = new System.Windows.Forms.Timer(this.components);
??? this.SuspendLayout();
??? //
??? // label1
??? //
??? this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
??? this.label1.Location = new System.Drawing.Point(8, 8);
??? this.label1.Name = "label1";
??? this.label1.Size = new System.Drawing.Size(256, 64);
??? this.label1.TabIndex = 0;
??? this.label1.Text = "正在備份數(shù)據(jù),請(qǐng)稍侯......";
??? this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
??? //
??? // pictureBox1
??? //
??? this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
??? this.pictureBox1.Location = new System.Drawing.Point(24, 16);
??? this.pictureBox1.Name = "pictureBox1";
??? this.pictureBox1.Size = new System.Drawing.Size(64, 48);
??? this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
??? this.pictureBox1.TabIndex = 1;
??? this.pictureBox1.TabStop = false;
??? //
??? // timer1
??? //
??? this.timer1.Interval = 300;
??? this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
??? //
??? // frmBackUp
??? //
??? this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
??? this.ClientSize = new System.Drawing.Size(272, 80);
??? this.Controls.Add(this.pictureBox1);
??? this.Controls.Add(this.label1);
??? this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
??? this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
??? this.Name = "frmBackUp";
??? this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
??? this.Text = "備份數(shù)據(jù)...";
??? this.Load += new System.EventHandler(this.frmBackUp_Load);
??? this.ResumeLayout(false);

?? }
?? #endregion

?? private void timer1_Tick(object sender, System.EventArgs e)
?? {
??? this.pictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipXY);
??? this.pictureBox1.Refresh();
?? }

//?? public void setType(SetType)
//?? {
//???
?? private void frmBackUp_Load(object sender, System.EventArgs e)
?? {
??? if(this.type==(int)SetType.BackUp)
???? this.label1.Text="正在備份數(shù)據(jù),請(qǐng)稍侯......";
??? else if(this.type==(int)SetType.Reinstate)
???? this.label1.Text="正在恢復(fù)數(shù)據(jù),請(qǐng)稍侯......";
??? this.timer1.Start();
?? }
}
}

?

BackUpAndReinstate組件中的類(lèi):(BackUp類(lèi)和Reinstate類(lèi))

BackUp類(lèi):

using System;
using System.Data;
using System.Data.SqlClient;

namespace BackUpAndReinstate
{
/// <summary>
/// 數(shù)據(jù)備份類(lèi)
/// </summary>
public class BackUp
{
?? private SqlConnection con=null;?????? //數(shù)據(jù)庫(kù)連接對(duì)象
?? private string filepath=null;??????? //備份路徑

?? //單參構(gòu)造
?? public BackUp(string filepath)
?? {
??? con=new SqlConnection("database=master;user id=sa;password=sa;data source=(local)");
??? this.filepath=filepath;
?? }

?? //數(shù)據(jù)備份方法
?? public string DataBaseBackUp()
?? {
??? string str="";
??? SqlCommand cmd=new SqlCommand();
??? cmd.Connection=con;
??? cmd.CommandText="select name from sysdevices where name='TeachingBusiness'";
??? con.Open();
??? SqlDataReader rdr=cmd.ExecuteReader();
??? if(!rdr.Read())
??? {
???? rdr.Close();
???? SqlCommand backcmd=new SqlCommand();
???? backcmd.Connection=con;
???? backcmd.CommandText="EXEC sp_addumpdevice @devtype,@logicalname,@physicalname";
???? SqlParameter param=backcmd.Parameters.Add("@devtype",SqlDbType.VarChar,20);
???? param.Value="disk";
???? param=backcmd.Parameters.Add("@logicalname",SqlDbType.VarChar,20);
???? param.Value="TeachingBusiness";
???? param=backcmd.Parameters.Add("@physicalname",SqlDbType.NVarChar,260);
???? param.Value=this.filepath;
???? backcmd.ExecuteNonQuery();
??? }
??? rdr.Close();
??? try
??? {
???? cmd.ExecuteNonQuery();
??? }
??? catch(SqlException er)
??? {
???? str=er.Message;
???? return str;
??? }
??? cmd.CommandText="backup database TeachingBusiness to TeachingBusiness";
??? try
??? {
???? cmd.ExecuteNonQuery();
??? }
??? catch(SqlException er)
??? {
???? str=er.Message;
???? return str;
??? }
??? finally
??? {
???? con.Close();
??? }
??? str="已備份成功!";
??? return str;
?? }
}
}

Reinstate類(lèi):

using System;
using System.Data;
using System.Data.SqlClient;

namespace BackUpAndReinstate
{
/// <summary>
/// 數(shù)據(jù)恢復(fù)類(lèi)
/// </summary>
public class Reinstate
{
?? private SqlConnection con=null;??????? //數(shù)據(jù)庫(kù)連接對(duì)象

?? //默認(rèn)構(gòu)造
?? public Reinstate()
?? {
??? con=new SqlConnection("database=master;user id=sa;password=sa;data source=(local)");
?? }

?? //數(shù)據(jù)恢復(fù)方法
?? public string DataBaseReinstate()
?? {
??? string str="";
??? SqlCommand cmd=new SqlCommand();
??? cmd.Connection=con;
??? cmd.CommandText="RESTORE DATABASE TeachingBusiness FROM TeachingBusiness with replace";
??? con.Open();
??? try
??? {
???? cmd.ExecuteNonQuery();
??? }
??? catch(SqlException er)
??? {
???? str=er.Message;
???? return str;
??? }
??? finally
??? {
???? con.Close();
??? }
??? str="已成功恢復(fù)數(shù)據(jù)庫(kù)";
??? return str;
?? }
}
}

BackUpAndReinstate組件中的類(lèi):(BackUp類(lèi)和Reinstate類(lèi))

BackUp類(lèi):

using System;
using System.Data;
using System.Data.SqlClient;

namespace BackUpAndReinstate
{
/// <summary>
/// 數(shù)據(jù)備份類(lèi)
/// </summary>
public class BackUp
{
?? private SqlConnection con=null;?????? //數(shù)據(jù)庫(kù)連接對(duì)象
?? private string filepath=null;??????? //備份路徑

?? //單參構(gòu)造
?? public BackUp(string filepath)
?? {
??? con=new SqlConnection("database=master;user id=sa;password=sa;data source=(local)");
??? this.filepath=filepath;
?? }

?? //數(shù)據(jù)備份方法
?? public string DataBaseBackUp()
?? {
??? string str="";
??? SqlCommand cmd=new SqlCommand();
??? cmd.Connection=con;
??? cmd.CommandText="select name from sysdevices where name='TeachingBusiness'";
??? con.Open();
??? SqlDataReader rdr=cmd.ExecuteReader();
??? if(!rdr.Read())
??? {
???? rdr.Close();
???? SqlCommand backcmd=new SqlCommand();
???? backcmd.Connection=con;
???? backcmd.CommandText="EXEC sp_addumpdevice @devtype,@logicalname,@physicalname";
???? SqlParameter param=backcmd.Parameters.Add("@devtype",SqlDbType.VarChar,20);
???? param.Value="disk";
???? param=backcmd.Parameters.Add("@logicalname",SqlDbType.VarChar,20);
???? param.Value="TeachingBusiness";
???? param=backcmd.Parameters.Add("@physicalname",SqlDbType.NVarChar,260);
???? param.Value=this.filepath;
???? backcmd.ExecuteNonQuery();
??? }
??? rdr.Close();
??? try
??? {
???? cmd.ExecuteNonQuery();
??? }
??? catch(SqlException er)
??? {
???? str=er.Message;
???? return str;
??? }
??? cmd.CommandText="backup database TeachingBusiness to TeachingBusiness";
??? try
??? {
???? cmd.ExecuteNonQuery();
??? }
??? catch(SqlException er)
??? {
???? str=er.Message;
???? return str;
??? }
??? finally
??? {
???? con.Close();
??? }
??? str="已備份成功!";
??? return str;
?? }
}
}

Reinstate類(lèi):

using System;
using System.Data;
using System.Data.SqlClient;

namespace BackUpAndReinstate
{
/// <summary>
/// 數(shù)據(jù)恢復(fù)類(lèi)
/// </summary>
public class Reinstate
{
?? private SqlConnection con=null;??????? //數(shù)據(jù)庫(kù)連接對(duì)象

?? //默認(rèn)構(gòu)造
?? public Reinstate()
?? {
??? con=new SqlConnection("database=master;user id=sa;password=sa;data source=(local)");
?? }

?? //數(shù)據(jù)恢復(fù)方法
?? public string DataBaseReinstate()
?? {
??? string str="";
??? SqlCommand cmd=new SqlCommand();
??? cmd.Connection=con;
??? cmd.CommandText="RESTORE DATABASE TeachingBusiness FROM TeachingBusiness with replace";
??? con.Open();
??? try
??? {
???? cmd.ExecuteNonQuery();
??? }
??? catch(SqlException er)
??? {
???? str=er.Message;
???? return str;
??? }
??? finally
??? {
???? con.Close();
??? }
??? str="已成功恢復(fù)數(shù)據(jù)庫(kù)";
??? return str;
?? }
}
}

?

c#中數(shù)據(jù)庫(kù)的備份和恢復(fù)


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 日韩免费精品一级毛片 | 亚洲 欧美日韩 国产 中文 | 久久视频在线免费观看 | 日韩av中文在线 | 一区二区三区四区高清视频 | 久久丁香| av在线免费播放网站 | 色综合久久88色综合天天 | 亚洲欧洲高清有无 | 波多野一区 | 久久秋霞理论电影 | 亚洲精品一区二区三区在线观看 | 激情丁香六月 | 9久9久女女热精品视频免费观看 | 国产精品福利短视在线播放频 | 欧美操操操 | 亚洲成人一区二区 | 欧美日韩精 | 丁香婷婷色综合亚洲小说 | 福利视频区 | 亚洲黄区| 97色伦色在线综合视频 | 国产亚洲女人久久久久久 | 99视频这里有精品 | 2019中文字幕在线视频 | 性 毛片| 中文字幕网在线 | 国产精品高清m3u8在线播放 | 97碰碰在线视视频 | 亚洲国产精品一区二区第一页 | 亚洲在线偷拍自拍 | 91久久精品日日躁夜夜躁国产 | 久久久国产99久久国产首页 | 国产午夜精品理论片免费观看 | 亚洲欧美在线观看 | 成在线视频 | 国产午夜亚洲精品国产 | 久久色网 | 狠狠干天天色 | 日本道二区视频 | 99爱在线精品视频免费观看9 |