Skip to content

Commit

Permalink
Move testing of active node in try block
Browse files Browse the repository at this point in the history
  • Loading branch information
dlenkov committed Sep 15, 2022
1 parent 1190c43 commit 80cd226
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions source/DSCResources/DSC_SqlAGListener/DSC_SqlAGListener.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
#>
function Get-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-SQLAlwaysOnAvailabilityGroupListener is called')]
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
Expand All @@ -51,13 +50,13 @@ function Get-TargetResource
$script:localizedData.GetAvailabilityGroupListener -f $Name, $AvailabilityGroup, $InstanceName
)

$serverObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName

# Is this node actively hosting the SQL instance?
$isActiveNode = Test-ActiveNode -ServerObject $serverObject

try
{
$serverObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName

# Is this node actively hosting the SQL instance?
$isActiveNode = Test-ActiveNode -ServerObject $serverObject

$availabilityGroupListener = Get-SQLAlwaysOnAvailabilityGroupListener -Name $Name -AvailabilityGroup $AvailabilityGroup -ServerName $ServerName -InstanceName $InstanceName

if ($null -ne $availabilityGroupListener)
Expand Down

0 comments on commit 80cd226

Please sign in to comment.