private void DeleteDatabase(string connectionString, string database) { try { Log.WriteStart("Deleting SQL server database"); Log.WriteInfo(string.Format("Deleting \"{0}\" SQL server database", database)); if (SqlUtils.DatabaseExists(connectionString, database)) { SqlUtils.DeleteDatabase(connectionString, database); Log.WriteEnd("Deleted database"); InstallLog.AppendLine(string.Format("- Deleted \"{0}\" SQL server database ", database)); } } catch (Exception ex) { if (Utils.IsThreadAbortException(ex)) { return; } Log.WriteError("Database delete error", ex); InstallLog.AppendLine(string.Format("- Failed to delete \"{0}\" SQL server database ", database)); throw; } }
private static void DeleteDatabase(string connectionString, string name) { try { Log.WriteStart("Deleting database"); Log.WriteInfo(string.Format("Deleting database \"{0}\"", name)); if (SqlUtils.DatabaseExists(connectionString, name)) { SqlUtils.DeleteDatabase(connectionString, name); Log.WriteEnd("Deleted database"); } } catch (Exception ex) { if (Utils.IsThreadAbortException(ex)) { return; } Log.WriteError("Database delete error", ex); throw; } }
private static void RestoreDatabase(string connectionString, string name, string bakFile, string position) { try { Log.WriteStart("Restoring database"); Log.WriteInfo(string.Format("Restoring database \"{0}\"", name)); if (SqlUtils.DatabaseExists(connectionString, name)) { SqlUtils.RestoreDatabase(connectionString, name, bakFile, position); Log.WriteEnd("Restored database"); } } catch (Exception ex) { if (Utils.IsThreadAbortException(ex)) { return; } Log.WriteError("Database restore error", ex); throw; } }
protected internal override void OnBeforeMoveNext(CancelEventArgs e) { try { if (!CheckFields()) { e.Cancel = true; return; } string connectionString = CreateConnectionString(); string component = SetupVariables.ComponentFullName; if (CheckConnection(connectionString)) { // check SQL server version string sqlVersion = GetSqlServerVersion(connectionString); if (!sqlVersion.StartsWith("9.") && !sqlVersion.StartsWith("10.") && !sqlVersion.StartsWith("11.") && !sqlVersion.StartsWith("12.") && !sqlVersion.StartsWith("13.") && !sqlVersion.StartsWith("14.") && !sqlVersion.StartsWith("15.")) { // SQL Server 2005 engine required e.Cancel = true; ShowWarning("This program can be installed on SQL Server 2005/2008/2012/2014/2016/2017/2019 only."); return; } int securityMode = GetSqlServerSecurityMode(connectionString); if (securityMode != 0) { // mixed mode required e.Cancel = true; ShowWarning("Please switch SQL Server authentication to mixed SQL Server and Windows Authentication mode."); return; } } else { e.Cancel = true; ShowWarning("SQL Server does not exist or access denied"); return; } string database = this.txtDatabase.Text; if (SqlUtils.DatabaseExists(connectionString, database)) { e.Cancel = true; ShowWarning(string.Format("{0} database already exists.", database)); return; } string server = this.txtSqlServer.Text; Log.WriteInfo(string.Format("Sql server \"{0}\" selected for {1}", server, component)); SetupVariables.Database = database; SetupVariables.DatabaseServer = server; SetupVariables.DbInstallConnectionString = connectionString; //AppConfig.SetComponentSettingStringValue(SetupVariables.ComponentId, "Database", database); //AppConfig.SetComponentSettingStringValue(SetupVariables.ComponentId, "DatabaseServer", server); //AppConfig.SetComponentSettingStringValue(SetupVariables.ComponentId, "InstallConnectionString", connectionString); } catch { e.Cancel = true; ShowError("Unable to configure the database server."); return; } base.OnBeforeMoveNext(e); }