Esempio n. 1
0
        public static void RestoreDb(string file)
        {
            sqlConnectionInfo();
            var restore = new Restore()
            {
                Database = BackupDatabase.database(), Action = RestoreActionType.Database, ReplaceDatabase = true
            };

            restore.Devices.AddDevice(file, DeviceType.File);
            svr().KillAllProcesses(BackupDatabase.database());
            restore.Wait();

            restore.SqlRestore(svr());
        }
Esempio n. 2
0
        public static string BackupDb()
        {
            DatabaseModelDataContext db = new DatabaseModelDataContext();
            var connectionstring        = db.Connection.ConnectionString;
            var backup = new Backup()
            {
                Action               = BackupActionType.Database,
                Database             = BackupDatabase.database(),
                BackupSetDescription = BackupDatabase.database() + " " + DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss tt")
            };
            string path = HttpContext.Current.Request.MapPath("~/DatabaseBackup/") + database() + " " + DateTime.Now.ToString("MM-dd-yyyy hh-mm-ss tt") + ".bak";

            backup.Devices.AddDevice(path, DeviceType.File);

            backup.SqlBackup(svr());
            return(path);
        }