SQL备份与恢复31210.doc

上传人:pu****.1 文档编号:543747234 上传时间:2023-03-28 格式:DOC 页数:5 大小:27KB
返回 下载 相关 举报
SQL备份与恢复31210.doc_第1页
第1页 / 共5页
SQL备份与恢复31210.doc_第2页
第2页 / 共5页
SQL备份与恢复31210.doc_第3页
第3页 / 共5页
SQL备份与恢复31210.doc_第4页
第4页 / 共5页
SQL备份与恢复31210.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《SQL备份与恢复31210.doc》由会员分享,可在线阅读,更多相关《SQL备份与恢复31210.doc(5页珍藏版)》请在金锄头文库上搜索。

1、SQL备份与恢复31210SQL备份与恢复.txt private void btbarBackup_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) string path = System.AppDomain.CurrentDomain.BaseDirectory + BackupDB; if(!System.IO .Directory.Exists(path) System.IO.Directory.CreateDirectory(path); path = path + + DateTime.Now.T

2、oString(yyyyMMddHHmmss) + .bak; string sql = backup database ScaleCoalTaxManage TO Disk= + path + ; if(this._db .ExcuteSql(sql) MessageBox.Show(数据库已经备份到:+path); private void brbarRecove_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) string path = System.AppDomain.CurrentDomain.Ba

3、seDirectory + BackupDB; if (!System.IO.Directory.Exists(path) System.IO.Directory.CreateDirectory(path); OpenFileDialog open = new OpenFileDialog(); open.InitialDirectory = path; open.Filter = bak files (*.bak)|*.bak; open.FilterIndex = 2; open.RestoreDirectory = true; if (open.ShowDialog() = Dialog

4、Result.OK) if (DialogResult.Yes = MessageBox.Show(此操作有可能使数据库部分数据丢失,是否继续?, 提示信息, MessageBoxButtons.YesNo) #region string restorepath = open.FileName; DBInfo dbinfo = new DBInfo(); string strConn = Server= + dbinfo.Server + ;User Id= + dbinfo.User + ;Password= + dbinfo.Pwd + ;DataBase=master; using (S

5、qlConnection conn = new SqlConnection(strConn) if (conn.State = ConnectionState.Closed) conn.Open(); bool res = Create(conn); if (res) string sql = RESTORE DATABASE ScaleCoalTaxManage FROM Disk= + restorepath + ; SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; try cmd.CommandText = exec p_

6、killspid ScaleCoalTaxManage + sql; cmd.ExecuteNonQuery(); MessageBox.Show(恢复成功); catch (System.Exception ex) MessageBox.Show(ex.Message); else MessageBox.Show(断开所有连接失败); #endregion public bool Create(SqlConnection conn) SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; try cmd.CommandText =

7、use master if exists (select * from dbo.sysobjects where id =object_id(Ndbo.p_killspid) and OBJECTPROPERTY(id, NIsProcedure) = 1) drop procedure dbo.p_killspid; cmd.ExecuteNonQuery(); cmd.CommandText = create proc p_killspid(dbname varchar(20) as declare s nvarchar(1000) declare tb cursor local for select s=kill +cast(spid as varchar) from master.sysprocesses where dbid=db_id(dbname) open tb fetch next from tb into s while fetch_status=0 begin exec(s) fetch next from tb into s end close tb deallocate tb; cmd.ExecuteNonQuery(); return true; catch (System.Exception ex) return false;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号