/// <summary> /// 数据还原 /// </summary> /// <param name="fileName"></param> protected void DataHy(string fileName) { string strSql = @"SELECT spid FROM master.dbo.sysprocesses , master.dbo.sysdatabases WHERE sysprocesses.dbid=sysdatabases.dbid AND sysdatabases.Name='" + CommTools.GetConfigName("dbName") + "'"; Database db = DatabaseFactory.CreateDatabase("conMaster"); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); IDataReader dr; dr = db.ExecuteReader(dbCommand); ArrayList list = new ArrayList(); while (dr.Read()) { list.Add(dr.GetInt16(0)); } dr.Close(); for (int i = 0; i < list.Count; i++) { dbCommand = db.GetSqlStringCommand(string.Format("KILL {0}", list[i])); db.ExecuteNonQuery(dbCommand); } string restoreSql = @"use master;restore database " + CommTools.GetConfigName("dbName") + " from disk='" + fileName + "' WITH REPLACE "; DbCommand cmdRT = db.GetSqlStringCommand(restoreSql.ToString()); try { db.ExecuteNonQuery(cmdRT); MessageBox.Show(this, "数据还原成功"); } catch (Exception ex) { MessageBox.Show(this, "数据还原失败"); } }
protected void DataBackUp(string filepath) { try { string strSql = @"backup database " + CommTools.GetConfigName("dbName") + " to disk='" + filepath + "' with init"; Database db = DatabaseFactory.CreateDatabase("conMaster"); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.ExecuteNonQuery(dbCommand); string msg = string.Empty; Sys_Backup entity = new Sys_Backup(); Sys_BackupBLL bll = new Sys_BackupBLL(); entity.Backup_AddTime = DateTime.Now; entity.Backup_AddUserID = CurrUserInfo().UserID; entity.Backup_Name = lblFileName.Text; entity.Backup_Path = filepath; entity.BackupID = Guid.NewGuid().ToString(); if (!bll.Add(entity, out msg)) { MessageBox.Show(this, msg); } MessageBox.Show(this, "数据备份成功"); } catch (Exception ex) { MessageBox.Show(this, "数据备份失败"); } }
protected void gridFiles_RowEditing(object sender, GridViewEditEventArgs e) { string fileName = gridFiles.DataKeys[e.NewEditIndex].Value.ToString(); string filePath = Server.MapPath(CommTools.GetConfigName("dbPath")) + "\\" + fileName; DataHy(filePath); InitBind(); }
/// <summary> /// /// </summary> protected void InitBind() { //得到文件的名称 string fileName = DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second; string filePath = Server.MapPath(CommTools.GetConfigName("dbPath")); lblFileName.Text = fileName; lblFilePath.Text = filePath; }
/// <summary> /// 数据绑定 /// </summary> protected void InitBind() { string path = Server.MapPath(CommTools.GetConfigName("dbPath")); GetFiles(path); }