首页 > 代码库 > net 对mssql 的操作(备份,还原,获取表数据,获取表字段信息)
net 对mssql 的操作(备份,还原,获取表数据,获取表字段信息)
#region 数据库管理 /// <summary> /// 还原恢复数据库 /// </summary> /// <param name="FilePath">保存路径</param> /// <returns></returns> public bool DataRestore(string FilePath) { string[] Connection = ConfigHelper.GetAppSettings("SqlServer_WYL_DB").Split(';'); SqlServerBackup sqlserverbackup = new SqlServerBackup(); sqlserverbackup.Server = Connection[0].Substring(7); sqlserverbackup.Database = Connection[1].Substring(9); sqlserverbackup.Uid = Connection[2].Substring(4); sqlserverbackup.Pwd = Connection[3].Substring(4); if (sqlserverbackup.DbRestore(FilePath)) return true; else return false; } /// <summary> /// 备份数据库 /// </summary> /// <param name="FilePath">保存路径</param> /// <returns></returns> public bool DataBackups(string FilePath) { try { string[] Connection = ConfigHelper.GetAppSettings("SqlServer_WYL_DB").Split(';'); SqlServerBackup sqlserverbackup = new SqlServerBackup(); sqlserverbackup.Server = Connection[0].Substring(7); sqlserverbackup.Database = Connection[1].Substring(9); sqlserverbackup.Uid = Connection[2].Substring(4); sqlserverbackup.Pwd = Connection[3].Substring(4); if (sqlserverbackup.DbBackup(FilePath)) return true; else return false; } catch (Exception) { return false; } } /// <summary> /// 添加数据库备份恢复记录 /// </summary> /// <param name="Type">类型:备份、恢复</param> /// <param name="File">文件名</param> /// <param name="Size">文件大小</param> /// <param name="CreateUserName">创建用户</param> /// <param name="DB">所属数据库</param> /// <param name="Memo">备注</param> /// <returns></returns> public void Add_Backup_Restore_Log(string Type, string File, string Size, string CreateUserName, string DB, string Memo) { LogHelper Logger = new LogHelper("Backup_Restore_Log"); Hashtable ht = new Hashtable(); StringBuilder sb = new StringBuilder(); sb.Append(Type + "∫"); sb.Append(File + "∫"); sb.Append(Size + "∫"); sb.Append(CreateUserName + "∫"); sb.Append(DB + "∫"); sb.Append(Memo + "∫"); sb.Append(DateTime.Now + "∫"); sb.Append("∮"); Logger.WriteLog(sb.ToString()); } /// <summary> /// 数据库备份还原记录 /// </summary> /// <returns></returns> public DataTable GetBackup_Restore_Log_List() { LogHelper Logger = new LogHelper("Backup_Restore_Log"); string filepath = ConfigHelper.GetAppSettings("LogFilePath") + "/Backup_Restore_Log.log"; StreamReader sr = new StreamReader(filepath, Encoding.GetEncoding("UTF-8"));//取得这txt文件的编码 string[] strvalue = http://www.mamicode.com/sr.ReadToEnd().ToString().Split('∮');>net 对mssql 的操作(备份,还原,获取表数据,获取表字段信息)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。