private void adHocQueryExecutionToolStripMenuItem_Click(object sender, EventArgs e) { MultiDbData multiDbData = GetServerDataCollection(); AdHocQueryExecution frmAdHoc = new AdHocQueryExecution(multiDbData, this.connData); frmAdHoc.ShowDialog(); }
private void buildValidationReportToolStripMenuItem_Click(object sender, EventArgs e) { MultiDbData multiDbData = GetServerDataCollection(); BuildValidationForm fbmBldValid = new BuildValidationForm(multiDbData, this.connData); fbmBldValid.ShowDialog(); }
private void saveConfigurationToolStripMenuItem_Click(object sender, EventArgs e) { if (null == GetServerDataCollection()) { return; } if (this.loadedFileName.Length > 0) { saveFileDialog1.FileName = this.loadedFileName; } if (DialogResult.OK == saveFileDialog1.ShowDialog()) { MultiDbData data = this.RunConfiguration; using (TextWriter writer = new StreamWriter(saveFileDialog1.FileName)) { XmlSerializer xmlS = new XmlSerializer(typeof(MultiDbData)); xmlS.Serialize(writer, data); } this.mruManager.Add(saveFileDialog1.FileName); this.loadedFileName = saveFileDialog1.FileName; } this.ValuesChanged = false; }
private void runBuildUsingCurrentConfigurationToolStripMenuItem_Click(object sender, EventArgs e) { this.runConfiguration = GetServerDataCollection(); if (this.runConfiguration == null) { return; } if (!MultiDbHelper.ValidateMultiDatabaseData(this.runConfiguration)) { MessageBox.Show("One or more scripts is missing a default or target override database setting.\r\nRun has been halted. Please correct the error and try again", "Missing Database setting", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (this.runConfiguration.Count == 1 && this.runConfiguration[0].OverrideSequence.Count == 0) { MessageBox.Show("Please configure a run order for at least one database item", "Unable to run", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } this.runConfiguration.RunAsTrial = true; this.runAsTrial = true; if (this.valuesChanged && ConfirmSave(ConfirmType.Run)) { this.DialogResult = DialogResult.OK; this.Close(); } else { this.DialogResult = DialogResult.OK; this.Close(); } }
private void runBuildUsingCurrentConfigurationCommitToolStripMenuItem_Click(object sender, EventArgs e) { this.runConfiguration = GetServerDataCollection(); if (this.runConfiguration == null) { return; } if (this.runConfiguration.Count == 1 && this.runConfiguration[0].OverrideSequence.Count == 0) { MessageBox.Show("Please configure a run order for at least one database item", "Unable to run", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } this.runConfiguration.RunAsTrial = false; this.runAsTrial = false; if (this.valuesChanged && ConfirmSave(ConfirmType.Run)) { this.DialogResult = DialogResult.OK; this.Close(); } else { this.DialogResult = DialogResult.OK; this.Close(); } }
private void generateObjectComparisonReportToolStripMenuItem_Click(object sender, EventArgs e) { MultiDbData multiDbData = GetServerDataCollection(); ObjectComparisonReportForm frmStat = new ObjectComparisonReportForm(multiDbData, this.connData); frmStat.ShowDialog(); }
public static MultiDbData CreateMultiDbConfigFromQuery(ConnectionData connData, string query, out string message) { try { log.LogInformation($"Generating database override configuation from {connData.SQLServerName} : {connData.DatabaseName}"); log.LogDebug($"Override generation script: {query}"); SqlConnection conn = ConnectionHelper.GetConnection(connData); SqlCommand cmd = new SqlCommand(query, conn); cmd.CommandType = CommandType.Text; DataTable tbl = new DataTable(); SqlDataAdapter adapt = new SqlDataAdapter(cmd); adapt.Fill(tbl); MultiDbData multi = new MultiDbData(); int counter = 0; foreach (DataRow row in tbl.Rows) { ServerData ser = multi[row[0].ToString().Trim()]; if (ser == null) { ser = new ServerData(); ser.ServerName = row[0].ToString().Trim(); } DatabaseOverride ovr; if (tbl.Columns.Count == 2) { ovr = new DatabaseOverride("client", row[1].ToString().Trim()); } else { ovr = new DatabaseOverride(row[1].ToString().Trim(), row[2].ToString().Trim()); ovr.AppendedQueryRowData(row.ItemArray, 3, tbl.Columns); } ser.OverrideSequence.Add(counter.ToString(), ovr); counter++; multi[ser.ServerName] = ser; } message = string.Empty; var dbs = multi.Sum(m => m.OverrideSequence.Count()); log.LogInformation($"Found {dbs} target databases across {multi.Count()} target servers"); return(multi); } catch (Exception exe) { message = exe.Message; return(null); } }
private void generateScriptStatusReportToolStripMenuItem_Click(object sender, EventArgs e) { MultiDbData multiDbData = GetServerDataCollection(); if (this.buildData == null) { MessageBox.Show("You do not have a Sql Build Project loaded. There's nothing to get status for.\r\nGo back and load an SBM or SBX file and try again.", "Nothing to Check", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } StatusReportForm frmStat = new StatusReportForm(this.buildData, multiDbData, this.projectFilePath, this.buildZipFileName, this.connData); frmStat.ShowDialog(); }
private void bgLoadCfg_DoWork(object sender, DoWorkEventArgs e) { List <ServerData> svrDataList = new List <ServerData>(); MultiDbData data = null; BackgroundWorker bg = (BackgroundWorker)sender; if (e.Argument is string) { bg.ReportProgress(-10, "Initializing"); string fileName = e.Argument.ToString(); bg.ReportProgress(10, "Loading " + Path.GetFileName(fileName) + "..."); data = MultiDbHelper.DeserializeMultiDbConfiguration(fileName); if (data == null) //maybe have a flat .cfg file?? { data = MultiDbHelper.ImportMultiDbTextConfig(fileName); } } else if (e.Argument is MultiDbData) { data = (MultiDbData)e.Argument; } if (data != null) { bg.ReportProgress(0, "Applying configuration... "); foreach (ServerData srv in data) { //We need to get the list of databases for this server if it doesn't match the current connection if (srv.ServerName != this.server) { bg.ReportProgress(10, "Retrieving database list from " + srv.ServerName); ConnectionData tmpC = new ConnectionData(); tmpC.Fill(this.connData); tmpC.SQLServerName = srv.ServerName; tmpC.DatabaseName = "master"; srv.Databases = InfoHelper.GetDatabaseList(tmpC); } else { srv.Databases = this.databaseList; } svrDataList.Add(srv); } e.Result = svrDataList; } }
private MultiDbData GetServerDataCollection() { try { SyncFormMultiDbPageData(); MultiDbData mult = new MultiDbData(); foreach (ListViewItem item in this.lstServers.Items) { mult.Add((ServerData)item.Tag); } return(mult); } catch (Exception) { MessageBox.Show("There is an error in your configuration.\r\nPlease make sure that you do not have any duplicate run order identifiers for the same default database", "Configration Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } }
public static MultiDbData DeserializeMultiDbConfiguration(string fileName) { MultiDbData data = null; try { using (TextReader reader = new StreamReader(fileName)) { XmlSerializer xmlS = new XmlSerializer(typeof(MultiDbData)); object tmp = xmlS.Deserialize(reader); if (tmp != null) { data = (MultiDbData)tmp; } } } catch { } return(data); }
public static string ConvertMultiDbDataToTextConfig(MultiDbData cfg) { StringBuilder sb = new StringBuilder(); StringBuilder sbOvr = new StringBuilder(); foreach (ServerData srv in cfg) { foreach (var seq in srv.OverrideSequence) { sbOvr.Length = 0; foreach (DatabaseOverride ovr in seq.Value) { sbOvr.Append(ovr.DefaultDbTarget + "," + ovr.OverrideDbTarget + ";"); } sbOvr.Length = sbOvr.Length - 1; sb.AppendLine(srv.ServerName + ":" + sbOvr.ToString()); } } return(sb.ToString()); }
public static bool ValidateMultiDatabaseData(MultiDbData dbData) { for (int i = 0; i < dbData.Count; i++) { if (dbData[i].OverrideSequence == null) { return(false); } SerializableDictionary <string, List <DatabaseOverride> > .Enumerator enumer = dbData[i].OverrideSequence.GetEnumerator(); while (enumer.MoveNext()) { if (!ConnectionHelper.ValidateDatabaseOverrides(dbData[i].OverrideSequence[enumer.Current.Key])) { return(false); } } } return(true); }
private void runBuildUsingCurrentConfigurationWithoutTransactionsToolStripMenuItem_Click(object sender, EventArgs e) { this.runConfiguration = GetServerDataCollection(); if (this.runConfiguration == null) { return; } if (this.runConfiguration.Count == 1 && this.runConfiguration[0].OverrideSequence.Count == 0) { MessageBox.Show("Please configure a run order for at least one database item", "Unable to run", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string message = "WARNING!\r\nWith this selection, you are disabling the transaction handling of Sql Build Manager.\r\nIn the event of a script failure, your scripts will NOT be rolled back\r\nand yout database will be left in an inconsistent state!\r\nAre you certain you want to continue?"; if (DialogResult.No == MessageBox.Show(message, "Are you sure you want this?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2)) { return; } this.runConfiguration.RunAsTrial = false; this.runAsTrial = false; this.runConfiguration.IsTransactional = false; this.isTransactional = false; if (this.valuesChanged && ConfirmSave(ConfirmType.Run)) { this.DialogResult = DialogResult.OK; this.Close(); } else { this.DialogResult = DialogResult.OK; this.Close(); } }
/// <summary> /// Takes a simplified delimited text format to create a multi-database run configuration. /// <example> /// Expects each line to be in a server: override format below: /// SERVER:defaultDb,override;default2,override2 /// </example> /// </summary> /// <param name="fileContents"></param> /// <returns></returns> public static MultiDbData ImportMultiDbTextConfig(string[] fileContents) { int dummySequence = 0; MultiDbData cfg = new MultiDbData(); for (int i = 0; i < fileContents.Length; i++) { string line = fileContents[i]; //Skip empty lines... if (line.Trim().Length == 0) { continue; } //need to have that colon! if (line.IndexOf(':') == -1) { throw new MultiDbConfigurationException("Error in configuration file line #" + i + 1 + ". Missing \":\" separator. This is needed to separate server from database override values."); } string server = line.Split(':')[0]; string dbs = line.Split(':')[1]; ServerData sData = cfg[server]; if (sData == null) { sData = new ServerData(); sData.ServerName = server.Trim(); cfg[server] = sData; } string[] arrDb = dbs.Split(';'); List <DatabaseOverride> tmpDb = new List <DatabaseOverride>(); for (int j = 0; j < arrDb.Length; j++) { //Changing so that a default setting is not required... //if (arrDb[j].IndexOf(',') == -1) // throw new MultiDbConfigurationException("Error in configuration file line #" + i + 1 + ". Missing \",\" separator. This is needed to separate default and override database targets."); string[] over = arrDb[j].Split(','); DatabaseOverride ovr; if (over.Length > 1) { ovr = new DatabaseOverride(over[0].Trim().Replace("'", ""), over[1].Trim()); } else { ovr = new DatabaseOverride("", over[0].Trim()); } tmpDb.Add(ovr); } if (tmpDb.Count > 0) { sData.OverrideSequence.Add(dummySequence.ToString(), tmpDb); dummySequence++; } //cfg.Add(sData); } return(cfg); }