/// <summary> /// Finish button click. /// </summary> protected void FinishNextButton_Click(object sender, EventArgs e) { if (!SqlInstallationHelper.DatabaseIsSeparated()) { string error = String.Empty; bool dbEngineSupportsOpenqueryCommand = !DatabaseSeparationHelper.IsUsingAzureDatabase; if (dbEngineSupportsOpenqueryCommand) { var separationHelper = new DatabaseSeparationHelper(); separationHelper.InstallScriptsFolder = SqlInstallationHelper.GetSQLInstallPathToObjects(); separationHelper.ScriptsFolder = Server.MapPath("~/App_Data/DBSeparation"); separationHelper.InstallationConnStringSeparate = EncryptionHelper.DecryptData(hdnConnString.Value); error = separationHelper.DeleteSourceTables(separationFinished.DeleteOldDB, false); } if (!String.IsNullOrEmpty(error)) { separationFinished.ErrorLabel.Visible = true; separationFinished.ErrorLabel.Text = error; EventLogProvider.LogEvent(EventType.ERROR, "Contact management database join", "DELETEOLDDATA", error, RequestContext.CurrentURL); } else { EnableTasks(); TakeSitesOnline(); WebFarmHelper.CreateTask(SystemTaskType.RestartApplication, "RestartApplication", "", null); ScriptHelper.RegisterStartupScript(this, typeof(string), "Close dialog", ScriptHelper.GetScript("RefreshParent(); CloseDialog();")); } } }
/// <summary> /// Finish button click. /// </summary> protected void FinishNextButton_Click(object sender, EventArgs e) { if (SqlInstallationHelper.DatabaseIsSeparated()) { string error = String.Empty; // If it doesn't support OpenQuery command, data could not have been moved so we cannot delete tables. if (SqlServerCapabilities.SupportsOpenQueryCommand) { var separationHelper = new DatabaseSeparationHelper(); separationHelper.InstallationConnStringSeparate = DatabaseSeparationHelper.ConnStringSeparate; separationHelper.InstallScriptsFolder = SqlInstallationHelper.GetSQLInstallPathToObjects(); separationHelper.ScriptsFolder = Server.MapPath("~/App_Data/DBSeparation"); error = separationHelper.DeleteSourceTables(false, true); } if (!String.IsNullOrEmpty(error)) { separationFinished.ErrorLabel.Visible = true; separationFinished.ErrorLabel.Text = error; EventLogProvider.LogEvent(EventType.ERROR, "Contact management database separation", "DELETEOLDDATA", error, RequestContext.CurrentURL); } else { EnableTasks(); TakeSitesOnline(); WebFarmHelper.CreateTask(SystemTaskType.RestartApplication, "RestartApplication"); ScriptHelper.RegisterStartupScript(this, typeof(string), "Close dialog", ScriptHelper.GetScript("RefreshParent(); CloseDialog();")); } } }
/// <summary> /// Joins databases. /// </summary> private void JoinDB() { var separation = new DatabaseSeparationHelper(); separation.InstallScriptsFolder = SqlInstallationHelper.GetSQLInstallPathToObjects(); separation.ScriptsFolder = Server.MapPath("~/App_Data/DBSeparation"); separation.LogMessage = progress.LogMessage; separation.JoinDatabase(); progress.LogMessage(GetString("separationDB.joinOK"), MessageTypeEnum.Finished, false); }
/// <summary> /// Separates database. /// </summary> private void SeparateDB() { separation = new DatabaseSeparationHelper(); separation.InstallationConnStringSeparate = databaseDialog.ConnectionString; separation.InstallScriptsFolder = SqlInstallationHelper.GetSQLInstallPathToObjects(); separation.ScriptsFolder = Server.MapPath("~/App_Data/DBSeparation"); separation.LogMessage = progress.LogMessage; separation.SeparateDatabase(); progress.LogMessage(ResHelper.GetString("SeparationDB.OK"), MessageTypeEnum.Finished, false); }
/// <summary> /// Finish button click. /// </summary> protected void FinishNextButton_Click(object sender, EventArgs e) { if (!SqlInstallationHelper.DatabaseIsSeparated()) { string error = String.Empty; // If it doesn't support OpenQuery command, data could not have been moved so we cannot delete tables. if (SqlServerCapabilities.SupportsOpenQueryCommand) { var separationHelper = new DatabaseSeparationHelper(); separationHelper.InstallScriptsFolder = SqlInstallationHelper.GetSQLInstallPathToObjects(); separationHelper.ScriptsFolder = Server.MapPath("~/App_Data/DBSeparation"); separationHelper.InstallationConnStringSeparate = UnprotectConnectionString(); error = separationHelper.DeleteSourceTables(separationFinished.DeleteOldDB, false); } if (!String.IsNullOrEmpty(error)) { separationFinished.ErrorLabel.Visible = true; separationFinished.ErrorLabel.Text = error; var logData = new EventLogData(EventTypeEnum.Error, "Contact management database join", "DELETEOLDDATA") { EventDescription = error, EventUrl = RequestContext.CurrentURL }; Service.Resolve <IEventLogService>().LogEvent(logData); } else { EnableTasks(); WebFarmHelper.CreateTask(new RestartApplicationWebFarmTask()); ScriptHelper.RegisterStartupScript(this, typeof(string), "Close dialog", ScriptHelper.GetScript("RefreshParent(); CloseDialog();")); } } }
/// <summary> /// Validates control. /// </summary> public bool ValidateForSeparation() { // Get database name if (radCreateNew.Checked && SqlServerCapabilities.SupportsDatabaseCreation) { Database = txtNewDatabaseName.Text; } else { Database = txtExistingDatabaseName.Text; } Database = TextHelper.LimitLength(Database, 100, String.Empty); if (String.IsNullOrEmpty(Database)) { DisplaySeparationError(GetString("Install.ErrorDBNameEmpty")); return(false); } // Set up the connection string ConnectionString = ConnectionHelper.BuildConnectionString(AuthenticationType, ServerName, Database, Username, Password, 240); // Test existing DB if (radUseExisting.Checked || !SqlServerCapabilities.SupportsDatabaseCreation) { if (SqlServerCapabilities.ControlServerPermissionAvailable && !DatabaseHelper.CheckDBPermission(DatabasePermission.ModifyDatabase, AuthenticationType, ServerName, Username, Password)) { DisplaySeparationError(GetString("separationDB.permissionmodify")); return(false); } if (!String.IsNullOrEmpty(ConnectionHelper.TestConnection(AuthenticationType, ServerName, Database, Username, Password))) { DisplaySeparationError(String.Format(ResHelper.GetFileString("Install.ErrorDatabseDoesntExist"), Database)); return(false); } if (DatabaseSeparationHelper.CheckCMDatabase(ConnectionString)) { DisplaySeparationError(GetString("separationDB.errorCMexists")); return(false); } } // Test new DB else { if (DatabaseHelper.DatabaseExists(ConnectionString)) { DisplaySeparationError(GetString("separationDB.ErrorDBExists")); return(false); } if (SqlServerCapabilities.ControlServerPermissionAvailable) { if (!DatabaseHelper.CheckDBPermission(DatabasePermission.ModifyDatabase, AuthenticationType, ServerName, Username, Password)) { DisplaySeparationError(GetString("separationDB.permissionmodify")); return(false); } if (!DatabaseHelper.CheckDBPermission(DatabasePermission.CreateDatabase, AuthenticationType, ServerName, Username, Password)) { DisplaySeparationError(GetString("separationDB.permissioncreate")); return(false); } } } // Test if tasks are stopped if (SchedulingHelper.EnableScheduler || SchedulingHelper.IsAnyTaskRunning()) { DisplaySeparationError(GetString("separationDB.stoptaskserror")); return(false); } iconHelp.Visible = btnStopTasks.Visible = true; // Test if separation process is not already started. if (DatabaseSeparationHelper.SeparationInProgress) { DisplaySeparationError(GetString("separationDB.processalreadystarted")); return(false); } return(true); }
/// <summary> /// Validates control. /// </summary> public bool ValidateForSeparation() { bool dbEngineSupportsDBCreation = !DatabaseSeparationHelper.IsUsingAzureDatabase; // Get database name if (radCreateNew.Checked && dbEngineSupportsDBCreation) { Database = txtNewDatabaseName.Text; } else { Database = txtExistingDatabaseName.Text; } Database = TextHelper.LimitLength(Database, 100, String.Empty); if (String.IsNullOrEmpty(Database)) { DisplaySeparationError(GetString("Install.ErrorDBNameEmpty")); return(false); } // Set up the connection string ConnectionString = ConnectionHelper.GetConnectionString(AuthenticationType, ServerName, Database, Username, Password, 240, false); // Test existing DB if (radUseExisting.Checked || !dbEngineSupportsDBCreation) { bool dbControlServerPermissionRequired = !DatabaseSeparationHelper.IsUsingAzureDatabase; if (dbControlServerPermissionRequired && !DatabaseHelper.CheckDBPermission(DatabasePermission.ModifyDatabase, AuthenticationType, ServerName, Username, Password)) { DisplaySeparationError(GetString("separationDB.permissionmodify")); return(false); } if (!String.IsNullOrEmpty(ConnectionHelper.TestConnection(AuthenticationType, ServerName, Database, Username, Password))) { DisplaySeparationError(String.Format(ResHelper.GetFileString("Install.ErrorDatabseDoesntExist"), Database)); return(false); } if (DatabaseSeparationHelper.CheckCMDatabase(ConnectionString)) { DisplaySeparationError(GetString("separationDB.errorCMexists")); return(false); } } // Test new DB else { if (DatabaseHelper.DatabaseExists(ConnectionString)) { DisplaySeparationError(GetString("separationDB.ErrorDBExists")); return(false); } if (!SystemContext.IsRunningOnAzure) { if (!DatabaseHelper.CheckDBPermission(DatabasePermission.ModifyDatabase, AuthenticationType, ServerName, Username, Password)) { DisplaySeparationError(GetString("separationDB.permissionmodify")); return(false); } if (!DatabaseHelper.CheckDBPermission(DatabasePermission.CreateDatabase, AuthenticationType, ServerName, Username, Password)) { DisplaySeparationError(GetString("separationDB.permissioncreate")); return(false); } } } // Test if tasks are stopped if (EnabledTasks()) { DisplaySeparationError(GetString("separationDB.stoptaskserror")); return(false); } iconHelp.Visible = btnStopTasks.Visible = true; // Test if separation process is not already started. if (DatabaseSeparationHelper.SeparationInProgress) { DisplaySeparationError(GetString("separationDB.processalreadystarted")); return(false); } return(true); }
/// <summary> /// Joins databases. /// </summary> private void JoinDB() { var separation = new DatabaseSeparationHelper(); separation.InstallScriptsFolder = SqlInstallationHelper.GetSQLInstallPathToObjects(); separation.ScriptsFolder = Server.MapPath("~/App_Data/DBSeparation"); separation.LogMessage = progress.LogMessage; separation.JoinDatabase(); progress.LogMessage(ResHelper.GetString("separationDB.joinOK"), MessageTypeEnum.Finished, false); }