Skip to content

Commit a7ea337

Browse files
authored
Merge pull request #123 from Icinga:feature/test_mssql_connection_on_connect
Feature: Adds support to test MSSQL connections Adds ability to return $null on open MSSQL connection instead of throwing exceptions for propoer testing
2 parents cdfcf8a + 10d9469 commit a7ea337

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/mssql/Open-IcingaMSSQLConnection.psm1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
the user the PowerShell is running with. If this is set and the user the PowerShell is
2626
running with can access to the MSSQL database you will not require to provide username
2727
and password
28+
.PARAMETER TestConnection
29+
Set this if you want to return $null on connection errors during MSSQL.open() instead of
30+
exception messages.
2831
.OUTPUTS
2932
System.Data.SqlClient.SqlConnection
3033
.LINK
@@ -38,7 +41,8 @@ function Open-IcingaMSSQLConnection()
3841
[string]$Address = "localhost",
3942
[int]$Port = 1433,
4043
[string]$SqlDatabase,
41-
[switch]$IntegratedSecurity = $FALSE
44+
[switch]$IntegratedSecurity = $FALSE,
45+
[switch]$TestConnection = $FALSE
4246
);
4347

4448
if ($IntegratedSecurity -eq $FALSE) {
@@ -80,6 +84,11 @@ function Open-IcingaMSSQLConnection()
8084

8185
$SqlConnection.Open();
8286
} catch {
87+
88+
if ($TestConnection) {
89+
return $null;
90+
}
91+
8392
Exit-IcingaThrowException `
8493
-InputString $_.Exception.Message `
8594
-StringPattern $Username `

0 commit comments

Comments
 (0)