private void BackupDataBase(string databaseName) { SplashScreenManager.ShowForm(typeof(F_wait_form)); var destinationPath = "HRM_PVMD_v" + DateTime.Now.Year + "." + DateTime.Now.Month + "." + DateTime.Now.Day + "." + DateTime.Now.Hour + "h." + DateTime.Now.Minute + "p.bak"; Server myServer = GetServer(); Backup backup = new Backup(); backup.Action = BackupActionType.Database; backup.Database = databaseName; // destinationPath = System.IO.Path.Combine(destinationPath, databaseName); backup.Devices.Add(new BackupDeviceItem(destinationPath, DeviceType.File)); backup.Initialize = true; backup.Checksum = true; backup.ContinueAfterError = true; backup.Incremental = false; backup.LogTruncation = BackupTruncateLogType.Truncate; // Perform backup. US_HT_BACKUP_HISTORY v_us = new US_HT_BACKUP_HISTORY(); try { v_us.strNGUOI_BACKUP = CAppContext_201.getCurrentUserName(); v_us.datNGAY_BACKUP = DateTime.Now.Date; v_us.strNOI_LUU = destinationPath; v_us.Insert(); backup.SqlBackup(myServer); } catch(Exception) { throw; } finally { SplashScreenManager.CloseForm(); } XtraMessageBox.Show("Sao lưu File : " + destinationPath + " thành công!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Information); }
//private void CreateLogin (string sqlLoginName, string sqlLoginPassword, string databaseName) //{ // Server myServer = GetServer(); // Login newLogin = myServer.Logins[sqlLoginName]; // if(newLogin != null) // newLogin.Drop(); // newLogin = new Login(myServer, sqlLoginName); // newLogin.PasswordPolicyEnforced = false; // newLogin.LoginType = LoginType.SqlLogin; // newLogin.Create(sqlLoginPassword); // //Create DatabaseUser // DatabaseMapping mapping = // new DatabaseMapping(newLogin.Name, MainDbName, newLogin.Name); // Database currentDb = myServer.Databases[databaseName]; // User dbUser = new User(currentDb, newLogin.Name); // dbUser.Login = sqlLogin; // dbUser.Create(); // dbUser.AddToRole("db_owner"); //} private void load_data_to_grid() { US_HT_BACKUP_HISTORY v_us = new US_HT_BACKUP_HISTORY(); DS_HT_BACKUP_HISTORY v_ds = new DS_HT_BACKUP_HISTORY(); v_us.FillDataset(v_ds); gridControl1.DataSource = v_ds.Tables[0]; }