private void ScanDatabases(object sender, DoWorkEventArgs e) { using (SqlConnection connection = Connection.Create(Settings.ActiveHost)) { try { connection.Open(); try { _disks = QueryEngine.GetDiskInfo(connection); } catch (Exception ex) { Utils.ShowErrorFrom(ex, "Refresh disk info failed"); } try { _databases = QueryEngine.GetDatabases(connection); } catch (Exception ex) { Utils.ShowErrorFrom(ex, "Refresh databases failed"); } if (_databases.Count > 0 && !Settings.ServerInfo.IsAzure) { try { QueryEngine.RefreshDatabaseSize(connection, _databases); } catch (Exception ex) { Utils.ShowErrorFrom(ex, "Refresh database sizes failed"); } } } catch (Exception ex) { Utils.ShowErrorFrom(ex, "Refresh failed"); } finally { connection.Close(); } } }
private void RefreshDatabases() { Stopwatch ts = Stopwatch.StartNew(); Output.Current.Add("Refresh databases"); grid.DataSource = null; buttonOK.Enabled = false; TotalSize.Visible = DataSize.Visible = LogSize.Visible = DataFreeSize.Visible = LogFreeSize.Visible = !Settings.ServerInfo.IsAzure; using (SqlConnection connection = Connection.Create(Settings.ActiveHost)) { try { connection.Open(); if (!Settings.ServerInfo.IsAzure && Settings.ServerInfo.IsSysAdmin) { Output.Current.Add("Get disk info"); try { List <DiskInfo> di = QueryEngine.GetDiskInfo(connection); if (di.Count > 0) { Text = $"{Resources.DatabaseBoxTitle} {string.Join(" | ", di.Select(_ => _.ToString()))}"; } } catch (Exception ex) { Output.Current.Add("Refresh disk info failed", ex.Message); } } List <Database> dbs = QueryEngine.GetDatabases(connection); var max = dbs.Max(_ => _.TotalSize); foreach (var rule in view.FormatRules) { ((FormatConditionRuleDataBar)rule.Rule).Maximum = max; } grid.DataSource = dbs; foreach (string db in Settings.ActiveHost.Databases) { int index = view.LocateByValue(DatabaseName.FieldName, db); view.SelectRow(index); } Output.Current.Add($"Found {dbs.Count} databases", null, ts.ElapsedMilliseconds); } catch (Exception ex) { Output.Current.Add("Refresh databases failed", ex.Message, ts.ElapsedMilliseconds); XtraMessageBox.Show(ex.Message.Replace(". ", "." + Environment.NewLine), ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { connection.Close(); } } }
private void ScanDatabases(object sender, DoWorkEventArgs e) { using (SqlConnection connection = Connection.Create(Settings.ActiveHost)) { try { connection.Open(); _disks = QueryEngine.GetDiskInfo(connection); _databases = QueryEngine.GetDatabases(connection); } catch (Exception ex) { Output.Current.Add("Refresh failed", ex.Message); XtraMessageBox.Show(ex.Message.Replace(". ", "." + Environment.NewLine), ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { connection.Close(); } } }