zoukankan      html  css  js  c++  java
  • C#备份和下载数据库

    备份:

    using (var conn = new SqlConnection(Firstelite.OMS.Business.Comman.SQLHelper.ConnectionString))
            {
                conn.Open();
                var sql = @"BACKUP DATABASE SMSUIALL
                  TO DISK = 'D:SMSUIALL.bak'
                     WITH FORMAT,
                        MEDIANAME = 'SQLServerBackups',
                        NAME = ''";
                var cmd = new SqlCommand(sql,conn);
                cmd.CommandTimeout = 300;
                cmd.ExecuteNonQuery();
            }

    下载:

    using (var conn = new SqlConnection(Firstelite.OMS.Business.Comman.SQLHelper.ConnectionString))
            {
                conn.Open();
                var sql = @"
                  DECLARE @data VARBINARY(MAX)
                  SELECT @data = BulkColumn
                  FROM OPENROWSET(BULK 'D:SMSUIALL.bak', SINGLE_BLOB) MyFile
                  SELECT @data";
                var cmd = new SqlCommand(sql,conn);
                cmd.CommandTimeout = 300;
                var data = (byte[])cmd.ExecuteScalar();
                File.WriteAllBytes(@"D:publishSMSUIALL.bak",data);
            }

     实例中数据库和网站不在同一台服务器上,所以说是下载。

    桂棹兮兰桨,击空明兮溯流光。
  • 相关阅读:
    图片《小美眉》
    redhat基本知识
    Linux 求助。设置分辨率?

    PHP close
    别想一个人承担一切
    java charAt返回char,不是int
    我的计算器
    支付宝面试小贴士
    java string charAt length()疑惑
  • 原文地址:https://www.cnblogs.com/nanfei/p/14694084.html
Copyright © 2011-2022 走看看