• ASP.NET中实现数据库备份


    static string pathBak;
        /// <summary>
        /// 备份SQL数据库
        /// </summary>
        /// <param name="databasename">要备份的数据源名称</param>
        /// <param name="backuptodatabase">备份到的数据库文件名称及路径.bak</param>
        /// <returns>返回生成的备份文件全路径名</returns>
        public string BakSql(string databaseName, string bakPath)
        {
            try
            {
                //声明临时数据库名称
                string bakName = string.Empty;
                if (bakPath.IndexOf(".bak") < 0)
                {
                    bakName = databaseName;
                    bakName += DateTime.Now.Year.ToString();
                    bakName += DateTime.Now.Month.ToString();
                    bakName += DateTime.Now.Day.ToString();
                    bakName += DateTime.Now.Hour.ToString();
                    bakName += DateTime.Now.Minute.ToString();
                    bakName += DateTime.Now.Second.ToString();
                    bakName += ".bak";
                    if (bakPath.LastIndexOf('\\') != bakPath.Length)
                        bakPath += '\\';
                }
                FileInfo fi = new FileInfo(bakPath);
                if (!Directory.Exists(fi.DirectoryName))
                    Directory.CreateDirectory(fi.DirectoryName);
                bakPath = bakPath + bakName;
                pathBak = bakPath;
                bakPath = bakPath.Replace("\\", "/");
                string sqlbak = string.Format("BACKUP DATABASE " + databaseName + " TO DISK = '{0}' WITH INIT", bakPath);
                if (SqlHelper.ExecuteNonQuery(Common.objCom.GetConnectionString("DBMaster"), CommandType.Text, sqlbak) != 0)
                    return pathBak;
                else
                    return string.Empty;
            }
            catch (Exception ex)
            {
                lbTip.Text = ex.Message;
                lbTip.ForeColor = Color.FromName("#FF8080");
                return string.Empty;
            }
        }

    http://zhidao.baidu.com/question/238879128.html

  • 相关阅读:
    Ninject Lazy Load问题
    log4net 极简配置
    log4net 使用指南,最常遇到的问题整理。。。
    【应聘】阿里巴巴Java面试题目
    【Unity3D】自动寻路(Nav Mesh Agent组件)
    【unity3D】鼠标控制camera的移动、放大(俯视浏览效果、LOL摄像机移动效果)
    【Unity3D】枪战游戏—弹孔设置
    【Unity3D】枪战游戏—发射子弹、射线检测
    【Unity3D】Unity自带组件—完成第一人称人物控制
    软件工程【第5章】- 需求工程与需求设计
  • 原文地址:https://www.cnblogs.com/xingshikk/p/2205297.html
Copyright © 2020-2023  润新知