asp.net 备份和恢复数据库的方法示例(3)

#region 备份Access数据库
        /// <summary>
        /// 备份Access数据库
        /// </summary>
        /// <param>要备份的数据库绝对路径</param>
        /// <param>备份到的数据库绝对路径</param>
        /// <returns></returns>
        public static void Backup(string srcPath,string aimPath)
        {

            if (!File.Exists(srcPath))
            {
                throw new Exception("源数据库不存在,无法备份");
            }
            try
            {
                File.Copy(srcPath,aimPath,true);
            }
            catch(IOException ixp)
            {
                throw new Exception(ixp.ToString());
            }

        }

#endregion

#region 还原Access数据库
        /// <summary>
        /// 还原Access数据库
        /// </summary>
        /// <param>备份的数据库绝对路径</param>
        /// <param>要还原的数据库绝对路径</param>
        public static void RecoverAccess(string bakPath,string dbPath)
        {         
            if (!File.Exists(bakPath))
            {
                throw new Exception("备份数据库不存在,无法还原");
            }
            try
            {
                File.Copy(bakPath, dbPath, true);
            }
            catch (IOException ixp)
            {
                throw new Exception(ixp.ToString());
            }      
        }      
        #endregion
    }
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjzxfx.html