备份:
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); }
实例中数据库和网站不在同一台服务器上,所以说是下载。