zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    地图 SDK 系列教程-在地图上展示指定区域
    [奇思妙想]下一个和微博、微信同级别的应用为是什么样的
    [办公自动化]EXCEL不大,但是保存很慢
    [奇思妙想]公共图书馆+快递
    [奇思妙想]“停哪了”
    [IT学习]阿铭Linux 微信公众号 每日一题 解析
    [IT学习]GIT 学习
    [故障处理]西部数据wd elements xp 无法识别
    [奇思妙想]无人机
    [IT学习]跟阿铭学linux(第3版)
  • 原文地址:https://www.cnblogs.com/xingshikk/p/2205297.html
Copyright © 2011-2022 走看看