From df1c1d80fe2e262b6a3c66c47cb0fa377bd13903 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Mon, 22 Jun 2026 14:30:58 +0200 Subject: [PATCH] Adds support for MSSQL shared memory feature, by not using a port for the connection string by using 0 or lower as port number --- doc/100-General/10-Changelog.md | 4 ++++ lib/mssql/Open-IcingaMSSQLConnection.psm1 | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/100-General/10-Changelog.md b/doc/100-General/10-Changelog.md index e02bfc01..592437d9 100644 --- a/doc/100-General/10-Changelog.md +++ b/doc/100-General/10-Changelog.md @@ -11,6 +11,10 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic [Issues and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/44) +### Enhancements + +* [#865](https://github.com/Icinga/icinga-powershell-framework/pull/865) Adds support for MSSQL shared memory feature, by not using a port for the connection string by using 0 or lower as port number + ### Bugfixes * [#877](https://github.com/Icinga/icinga-powershell-framework/pull/877) Fixes threshold comparison while using `%`-Values, which caused falsely report of `Warning` threshold being larger than `Critical` threshold diff --git a/lib/mssql/Open-IcingaMSSQLConnection.psm1 b/lib/mssql/Open-IcingaMSSQLConnection.psm1 index f2d38d6b..9fdb0757 100644 --- a/lib/mssql/Open-IcingaMSSQLConnection.psm1 +++ b/lib/mssql/Open-IcingaMSSQLConnection.psm1 @@ -66,7 +66,13 @@ function Open-IcingaMSSQLConnection() try { $SqlConnection = New-Object System.Data.SqlClient.SqlConnection; - $SqlConnection.ConnectionString = "Server=$Address,$Port;"; + + # Only add the port if it is above 0. Otherwise the fall back to the Shared Memory feature of MSSQL + if ($Port -le 0) { + $SqlConnection.ConnectionString = "Server=$Address;"; + } else { + $SqlConnection.ConnectionString = "Server=$Address,$Port;"; + } if ([string]::IsNullOrEmpty($SqlDatabase) -eq $FALSE) { $SqlConnection.ConnectionString += "Database=$SqlDatabase;";