Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dashboard/RemoveServerDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
<!-- Drop database checkbox -->
<CheckBox Grid.Row="1" x:Name="DropDatabaseCheckBox" Margin="0,0,0,5"
Foreground="{DynamicResource ForegroundBrush}">
<TextBlock Text="Also drop the PerformanceMonitor database on this server" TextWrapping="Wrap"/>
<TextBlock Text="Also drop the PerformanceMonitor database and SQL Agent jobs on this server" TextWrapping="Wrap"/>
</CheckBox>
<TextBlock Grid.Row="2" Text="Warning: all collected monitoring data on the server will be permanently deleted."
<TextBlock Grid.Row="2" Text="Warning: all collected monitoring data and scheduled collection jobs on the server will be permanently deleted."
FontSize="11" Foreground="{DynamicResource ErrorBrush}" Margin="20,0,0,15"
TextWrapping="Wrap" Visibility="{Binding ElementName=DropDatabaseCheckBox, Path=IsChecked, Converter={StaticResource BoolToVisibilityConverter}}"/>

Expand Down
13 changes: 12 additions & 1 deletion Dashboard/Services/ServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ public async Task DropMonitorDatabaseAsync(ServerConnection server)
using var connection = new SqlConnection(builder.ConnectionString);
await connection.OpenAsync();

// Remove SQL Agent jobs before dropping the database
using var jobCmd = new SqlCommand(@"
IF EXISTS (SELECT 1 FROM msdb.dbo.sysjobs WHERE name = N'PerformanceMonitor - Collection')
EXEC msdb.dbo.sp_delete_job @job_name = N'PerformanceMonitor - Collection', @delete_unused_schedule = 1;
IF EXISTS (SELECT 1 FROM msdb.dbo.sysjobs WHERE name = N'PerformanceMonitor - Data Retention')
EXEC msdb.dbo.sp_delete_job @job_name = N'PerformanceMonitor - Data Retention', @delete_unused_schedule = 1;
IF EXISTS (SELECT 1 FROM msdb.dbo.sysjobs WHERE name = N'PerformanceMonitor - Hung Job Monitor')
EXEC msdb.dbo.sp_delete_job @job_name = N'PerformanceMonitor - Hung Job Monitor', @delete_unused_schedule = 1;", connection);
jobCmd.CommandTimeout = 30;
await jobCmd.ExecuteNonQueryAsync();

// Close active connections before dropping
using var killCmd = new SqlCommand(@"
IF DB_ID('PerformanceMonitor') IS NOT NULL
Expand All @@ -162,7 +173,7 @@ IF DB_ID('PerformanceMonitor') IS NOT NULL
killCmd.CommandTimeout = 30;
await killCmd.ExecuteNonQueryAsync();

Logger.Info($"Dropped PerformanceMonitor database on '{server.DisplayName}'");
Logger.Info($"Dropped PerformanceMonitor database and Agent jobs on '{server.DisplayName}'");
}

public void UpdateLastConnected(string id)
Expand Down
13 changes: 9 additions & 4 deletions Installer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ INSERT...WHERE NOT EXISTS re-populates with current recommended values
*/
if (resetSchedule && fileName.StartsWith("04_", StringComparison.Ordinal))
{
sqlContent = "TRUNCATE TABLE config.collection_schedule;\nGO\n" + sqlContent;
sqlContent = "TRUNCATE TABLE [PerformanceMonitor].[config].[collection_schedule];\nGO\n" + sqlContent;
Console.Write("(resetting schedule) ");
}

Expand Down Expand Up @@ -1155,17 +1155,22 @@ private static List<string> GetApplicableUpgrades(
return upgradeFolders;
}

/*Parse current version - if invalid, skip upgrades*/
if (!Version.TryParse(currentVersion, out var current))
/*Parse current version - if invalid, skip upgrades
Normalize to 3-part (Major.Minor.Build) to avoid Revision mismatch:
folder names use 3-part "1.3.0" but DB stores 4-part "1.3.0.0"
Version(1,3,0).Revision=-1 which breaks >= comparison with Version(1,3,0,0)*/
if (!Version.TryParse(currentVersion, out var currentRaw))
{
return upgradeFolders;
}
var current = new Version(currentRaw.Major, currentRaw.Minor, currentRaw.Build);

/*Parse target version - if invalid, skip upgrades*/
if (!Version.TryParse(targetVersion, out var target))
if (!Version.TryParse(targetVersion, out var targetRaw))
{
return upgradeFolders;
}
var target = new Version(targetRaw.Major, targetRaw.Minor, targetRaw.Build);

/*
Find all upgrade folders matching pattern: {from}-to-{to}
Expand Down
12 changes: 9 additions & 3 deletions InstallerGui/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,20 @@ public partial class MainWindow : Window
private static readonly SolidColorBrush WarningBrush = new(Color.FromRgb(0xFF, 0xC1, 0x07)); // Yellow

/*
Cached version string
Cached version strings
Display version includes git hash suffix for UI/logs
Assembly version is clean (e.g. "2.0.0.0") for upgrade version comparison
*/
private static readonly string AppVersion =
Assembly.GetExecutingAssembly()
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion
?? Assembly.GetExecutingAssembly().GetName().Version?.ToString()
?? "Unknown";

private static readonly string AppAssemblyVersion =
Assembly.GetExecutingAssembly().GetName().Version?.ToString()
?? "Unknown";

private static readonly char[] NewLineChars = { '\r', '\n' };

public MainWindow()
Expand Down Expand Up @@ -260,7 +266,7 @@ private async void TestConnection_Click(object sender, RoutedEventArgs e)
var upgrades = InstallationService.GetApplicableUpgrades(
_monitorRootDirectory,
_installedVersion,
AppVersion);
AppAssemblyVersion);
if (upgrades.Count > 0)
{
LogMessage($"Found {upgrades.Count} upgrade(s) to apply", "Warning");
Expand Down Expand Up @@ -377,7 +383,7 @@ private async void Install_Click(object sender, RoutedEventArgs e)
_monitorRootDirectory,
_connectionString,
_installedVersion,
AppVersion,
AppAssemblyVersion,
progress,
cancellationToken);

Expand Down
13 changes: 9 additions & 4 deletions InstallerGui/Services/InstallationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ Execute SQL files
/*Reset schedule to defaults if requested*/
if (resetSchedule && fileName.StartsWith("04_", StringComparison.Ordinal))
{
sqlContent = "TRUNCATE TABLE config.collection_schedule;\nGO\n" + sqlContent;
sqlContent = "TRUNCATE TABLE [PerformanceMonitor].[config].[collection_schedule];\nGO\n" + sqlContent;
progress?.Report(new InstallationProgress
{
Message = "Resetting schedule to recommended defaults...",
Expand Down Expand Up @@ -1053,17 +1053,22 @@ public static List<UpgradeInfo> GetApplicableUpgrades(
return upgrades;
}

/*Parse current version - if invalid, skip upgrades*/
if (!Version.TryParse(currentVersion, out var current))
/*Parse current version - if invalid, skip upgrades
Normalize to 3-part (Major.Minor.Build) to avoid Revision mismatch:
folder names use 3-part "1.3.0" but DB stores 4-part "1.3.0.0"
Version(1,3,0).Revision=-1 which breaks >= comparison with Version(1,3,0,0)*/
if (!Version.TryParse(currentVersion, out var currentRaw))
{
return upgrades;
}
var current = new Version(currentRaw.Major, currentRaw.Minor, currentRaw.Build);

/*Parse target version - if invalid, skip upgrades*/
if (!Version.TryParse(targetVersion, out var target))
if (!Version.TryParse(targetVersion, out var targetRaw))
{
return upgrades;
}
var target = new Version(targetRaw.Major, targetRaw.Minor, targetRaw.Build);

/*
Find all upgrade folders matching pattern: {from}-to-{to}
Expand Down
Loading