diff --git a/.gitignore b/.gitignore index b8473b5..642bab9 100644 --- a/.gitignore +++ b/.gitignore @@ -131,7 +131,7 @@ publish/ # NuGet Packages Directory ## TODO: If you have NuGet Package Restore enabled, uncomment the next line -#packages/ +packages/ # Windows Azure Build Output csx diff --git a/src/Controls/OutlookGrid/DataSourceManager.cs b/src/Controls/OutlookGrid/DataSourceManager.cs index 5319dcc..72296d9 100644 --- a/src/Controls/OutlookGrid/DataSourceManager.cs +++ b/src/Controls/OutlookGrid/DataSourceManager.cs @@ -77,6 +77,9 @@ public object BoundItem public int Add(object val) { + if (val == null) + return -1; + return List.Add(val); } diff --git a/src/Controls/OutlookGrid/OutlookGrid.cs b/src/Controls/OutlookGrid/OutlookGrid.cs index e4d5d9f..c4f9276 100644 --- a/src/Controls/OutlookGrid/OutlookGrid.cs +++ b/src/Controls/OutlookGrid/OutlookGrid.cs @@ -135,6 +135,9 @@ public override void Sort(IComparer comparer) public override void Sort(DataGridViewColumn dataGridViewColumn, ListSortDirection direction) { + if (dataGridViewColumn == null) + return; + if (_dataSource == null) // if no datasource is set, then bind to the grid itself _dataSource = new DataSourceManager(this, null); diff --git a/src/Logic/MonitorEngine.cs b/src/Logic/MonitorEngine.cs index 78208b1..28e97f0 100644 --- a/src/Logic/MonitorEngine.cs +++ b/src/Logic/MonitorEngine.cs @@ -190,17 +190,26 @@ public void CheckServerHealth() var isAlert = false; //memory - long physicalMemory; - long availableMemory; + long physicalMemory = 0; + long availableMemory = 0; var serverState = e.Server as ServerState; if (!serverState.IsAzure) - QueryEngine.GetMemoryInfo(e.Server, out physicalMemory, out availableMemory); - else + try + { + QueryEngine.GetMemoryInfo(e.Server, out physicalMemory, out availableMemory); + } + catch(SqlException err) when (err.Number == 300) + { + // VIEW SERVER STATE permission was denied + } + object memoryMb = null; + try + { + memoryMb = SqlHelper.ExecuteScalar("SELECT (cntr_value/1024.0) FROM sys.dm_os_performance_counters WHERE counter_name = 'Total Server Memory (KB)'", e.Server); + } + catch (SqlException err) when (err.Number == 300) { - physicalMemory = 0; - availableMemory = 0; } - var memoryMb = SqlHelper.ExecuteScalar("SELECT (cntr_value/1024.0) FROM sys.dm_os_performance_counters WHERE counter_name = 'Total Server Memory (KB)'", e.Server); if (memoryMb != null) { var memory = Convert.ToInt32(memoryMb); @@ -209,15 +218,30 @@ public void CheckServerHealth() } //cpu - int cpuSqlProcess; - int cpuSystemIdle; - int cpuOtherProcesses; - QueryEngine.GetCpuInfo(e.Server, out cpuSqlProcess, out cpuSystemIdle, out cpuOtherProcesses); + int cpuSqlProcess = 0; + int cpuSystemIdle = 0; + int cpuOtherProcesses = 0; + try + { + QueryEngine.GetCpuInfo(e.Server, out cpuSqlProcess, out cpuSystemIdle, out cpuOtherProcesses); + } + catch (SqlException err) when (err.Number == 300) + { + } isAlert = cpuSystemIdle < Settings.Instance.FreeCpuRatio; healthItems.Add(new HealthItem { Category = HealthCategoryServer, HealthType = HealthTypes.ServerCpu, CurrentValue = cpuSystemIdle.ToString() + " %", ReferenceValue = cpuSqlProcess + " %", ItemName = "Server CPU", Description = "Free/DB Used", IsAlert = isAlert }); //disk space - var diskSpaces = QueryEngine.GetDiskSpace(e.Server); + var diskSpaces = new Dictionary>(); + try + { + diskSpaces = QueryEngine.GetDiskSpace(e.Server); + + } + catch (SqlException err) when (err.Number == 229) + { + // The EXECUTE permission was denied on the object 'xp_fixeddrives', database 'mssqlsystemresource', schema 'sys'. + } diskSpaces.Where(s => s.Value.Value > 0).ForEach(s => { isAlert = s.Value.Key < s.Value.Value / 100 * Settings.Instance.DatabaseDiskFreeSpaceRatio; @@ -227,7 +251,14 @@ public void CheckServerHealth() if (!e.Server.IsAzure) { //locked objects - var lockedObjects = SqlHelper.Query(QueryEngine.SqlLockedObjects, e.Server); + DataTable lockedObjects = new DataTable(); + try + { + lockedObjects = SqlHelper.Query(QueryEngine.SqlLockedObjects, e.Server); + } + catch (SqlException err) when (err.Number == 300) + { + } lockedObjects.Rows.Cast().ForEach(r => { isAlert = false; @@ -236,7 +267,14 @@ public void CheckServerHealth() } //blocked processes - var blockedProcesses = SqlHelper.Query(QueryEngine.SqlWaitingTasks + " WHERE blocking_session_id IS NOT NULL", e.Server); + var blockedProcesses = new DataTable(); + try + { + blockedProcesses = SqlHelper.Query(QueryEngine.SqlWaitingTasks + " WHERE blocking_session_id IS NOT NULL", e.Server); + } + catch (SqlException err) when (err.Number == 300) + { + } blockedProcesses.Rows.Cast().ForEach(r => { isAlert = true; @@ -252,7 +290,15 @@ public void CheckServerHealth() }); //db/log space - var dbLogSpaces = QueryEngine.GetDbLogSpace(e.Server); + var dbLogSpaces = new Dictionary>(); + try + { + dbLogSpaces = QueryEngine.GetDbLogSpace(e.Server); + } + catch(SqlException err) when (err.Number == 297) + { + // The user does not have permission to perform this action. + } dbLogSpaces.Where(s => !s.Value.Item3).ForEach(s => { healthItems.Add(new HealthItem { Category = HealthCategoryDatabase, HealthType = HealthTypes.DatabaseLogSpace, CurrentValue = s.Value.Item1.ToString() + " " + Utils.SizeMb, ReferenceValue = s.Value.Item2 + " " + Utils.SizeMb, ItemName = "DB/Log Space (" + s.Key + ")", Description = "Log/DB", IsAlert = true }); diff --git a/src/SQLMonitor.csproj b/src/SQLMonitor.csproj index ec73386..fcff414 100644 --- a/src/SQLMonitor.csproj +++ b/src/SQLMonitor.csproj @@ -88,8 +88,8 @@ false - - ..\..\..\Codes\net\bin\ICSharpCode.TextEditor.dll + + packages\ICSharpCode.TextEditor.3.2.1.6466\lib\Net20\ICSharpCode.TextEditor.dll @@ -258,6 +258,7 @@ ViewTextDialog.cs + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/src/UI/Monitor.cs b/src/UI/Monitor.cs index 00fcb12..13203df 100644 --- a/src/UI/Monitor.cs +++ b/src/UI/Monitor.cs @@ -3487,7 +3487,7 @@ private void OnAnalysisRowEnter(object sender, DataGridViewCellEventArgs e) case AnalysisTypes.IndexUsage: case AnalysisTypes.Performance: case AnalysisTypes.LogicFault: - text = dgvAnalysis.Rows[e.RowIndex].Cells["Suggestion"].Value.ToString(); + text = dgvAnalysis.Rows[e.RowIndex].Cells["Suggestion"].Value?.ToString(); break; case AnalysisTypes.LockedObjects: var spid = dgvAnalysis.Rows[e.RowIndex].Cells["SPID"].Value; diff --git a/src/packages.config b/src/packages.config new file mode 100644 index 0000000..0ea96fb --- /dev/null +++ b/src/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file