public void Execute(Dictionary <string, string> input) { if (!input.Any(x => x.Key == PARAMKEYS_CREATE)) { return; } connectionString = DatabaseInstaller.GetSetting(input, DatabaseInstaller.PARAMKEYS_APPDB, string.Empty); Log.Information($"connectionstring censored: {CensorConnectionString(connectionString)}"); masterConnectionString = DatabaseInstaller.GetSetting(input, PARAMKEYS_MASTERDB, string.Empty); Log.Information($"masterconnectionstring censored: {CensorConnectionString(masterConnectionString)}"); newDatabaseName = DatabaseInstaller.GetSetting(input, PARAMKEYS_NEWNAME, string.Empty); Log.Information($"newDatabaseName: {newDatabaseName}"); if (DatabaseServer.TestConnectionString(connectionString)) { throw new Exception("The connection string references an existing database."); } if (string.IsNullOrEmpty(newDatabaseName)) { throw new Exception("A new database name was not specified."); } var builder = new Npgsql.NpgsqlConnectionStringBuilder(connectionString); if (builder.Database.ToLower() != newDatabaseName.ToLower()) { throw new Exception("A new database name does not match the specified connection string."); } CreateDatabase(); }
/// <summary> /// Performs an install of a database /// </summary> public void Install(InstallSetup setup) { //The connection string must reference an existing database if (!DatabaseServer.TestConnectionString(setup.ConnectionString)) { throw new Exception("The connection string does not reference a valid database."); } try { UpgradeInstaller.UpgradeDatabase(setup); } catch (InvalidSQLException ex) { var sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine("BEGIN ERROR SQL"); sb.AppendLine(ex.SQL); sb.AppendLine("END ERROR SQL"); sb.AppendLine(); Log.Verbose(sb.ToString()); UpgradeInstaller.LogError(ex, sb.ToString()); throw; } catch (Exception ex) { throw; } }
private bool DbAvailable() { var retVal = false; for (var ii = 1; ii < 21; ii++) { if (DatabaseServer.TestConnectionString(connectionString)) { retVal = true; break; } Log.Information($"Unable to connect to postgress attempt {ii.ToString()} of 20"); System.Threading.Thread.Sleep(10000); } return(retVal); }