dbatools icon indicating copy to clipboard operation
dbatools copied to clipboard

Test-DbaReplLatency - Needs some love

Open jpomfret opened this issue 2 years ago • 0 comments

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

This command doesn't run for me at the moment - I get the following errors.

Test-DbaReplLatency -SqlInstance mssql1
SetValueInvocationException: C:\GitHub\DMM-GitHub\dbatools\public\Test-DbaReplLatency.ps1:109:17
Line |
 109 |                  $transPub.Name = $publication.PublicationName
     |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception setting "Name": ""Name" cannot be null or empty. (Parameter 'Name')"
SetValueInvocationException: C:\GitHub\DMM-GitHub\dbatools\public\Test-DbaReplLatency.ps1:110:17
Line |
 110 |                  $transPub.DatabaseName = $publication.Database
     |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception setting "DatabaseName": ""DatabaseName" cannot be null or empty. (Parameter 'DatabaseName')"
MethodInvocationException: C:\GitHub\DMM-GitHub\dbatools\public\Test-DbaReplLatency.ps1:117:21
Line |
 117 |                  if (!$transPub.LoadProperties()) {
     |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "LoadProperties" with "0" argument(s): "Must set property "Name" with a proper value in order to do any operation with the object."
MethodInvocationException: C:\GitHub\DMM-GitHub\dbatools\public\Test-DbaReplLatency.ps1:122:17
Line |
 122 |                  $transPub.PostTracerToken() | Out-Null
     |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "PostTracerToken" with "0" argument(s): "Must set property "Name" with a proper value in order to do any operation with the object."
SetValueInvocationException: C:\GitHub\DMM-GitHub\dbatools\public\Test-DbaReplLatency.ps1:148:17
Line |
 148 |                  $pubMon.Name = $publication.PublicationName
     |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception setting "Name": ""Name" cannot be null or empty. (Parameter 'Name')"
SetValueInvocationException: C:\GitHub\DMM-GitHub\dbatools\public\Test-DbaReplLatency.ps1:150:17
Line |
 150 |                  $pubMon.PublisherName = $publication.Server
     |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception setting "PublisherName": ""PublisherName" cannot be null or empty. (Parameter 'PublisherName')"
SetValueInvocationException: C:\GitHub\DMM-GitHub\dbatools\public\Test-DbaReplLatency.ps1:151:17
Line |
 151 |                  $pubMon.PublicationDBName = $publication.Database
     |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception setting "PublicationDBName": ""PublicationDBName" cannot be null or empty. (Parameter 'PublicationDBName')"
MethodInvocationException: C:\GitHub\DMM-GitHub\dbatools\public\Test-DbaReplLatency.ps1:158:21
Line |
 158 |                  if (!$pubMon.LoadProperties()) {
     |                      ~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "LoadProperties" with "0" argument(s): "Must set property "Name" with a proper value in order to do any operation with the object."
MethodInvocationException: C:\GitHub\DMM-GitHub\dbatools\public\Test-DbaReplLatency.ps1:162:17
Line |
 162 |                  $tokenList = $pubMon.EnumTracerTokens()
     |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "EnumTracerTokens" with "0" argument(s): "Must set property "Name" with a proper value in order to do any operation with the object."
InvalidOperation: C:\GitHub\DMM-GitHub\dbatools\public\Test-DbaReplLatency.ps1:165:21
Line |
 165 |                      $tokenList = $tokenList[0]
     |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot index into a null array.

Also under #8958 we rewrote a lot of the replication functions and have moved away from using New-SqlConnection so this should be rewritten without that and then it can be removed.

This is accomplished in Get-DbaReplServer as so

$server = Connect-DbaInstance -SqlInstance $instance -SqlCredential $SqlCredential
$replServer = New-Object Microsoft.SqlServer.Replication.ReplicationServer
$replServer.ConnectionContext = $Server.ConnectionContext.SqlConnectionObject
$replServer | Add-Member -Type NoteProperty -Name ComputerName -Value $server.ComputerName -Force
$replServer | Add-Member -Type NoteProperty -Name InstanceName -Value $server.ServiceName -Force
$replServer | Add-Member -Type NoteProperty -Name SqlInstance -Value $server.DomainInstanceName -Force

Steps to Reproduce

Set up transactional replication from mssql1 to mssql2 for a publication with an article & add a subscription

Enable-DbaReplDistributor -SqlInstance mssql1
Enable-DbaReplPublishing -SqlInstance mssql1 -whatif

$pub = @{
    SqlInstance = 'mssql1'
    Database    = 'pubs'
    name        = 'testPub'
    Type        = 'Transactional'
 }
New-DbaReplPublication @pub -verbose

$article = @{
    SqlInstance = 'mssql1'
    Database    = 'pubs'
    Publication = 'testpub'
    Name        = 'publishers'
    Filter      = "city = 'seattle'"
}
Add-DbaReplArticle @article

#transactional
$sub = @{
    SqlInstance               = 'mssql2'
    Database                  = 'pubs'
    PublicationDatabase       = 'pubs'
    PublisherSqlInstance      = 'mssql1'
    PublicationName           = 'testpub'
    Type                      = 'Push'
    SubscriptionSqlCredential = $credential

}
New-DbaReplSubscription @sub

make sure all looks good in Replication monitor: image

and confirmed tracer tokens work image

Run the command and you'll get errors :(

Test-DbaReplLatency -SqlInstance mssql1

image

Please confirm that you are running the most recent version of dbatools

2.0.3

Other details or mentions

No response

What PowerShell host was used when producing this error

VS Code (terminal)

PowerShell Host Version

Name Value


PSVersion 7.3.5 PSEdition Core GitCommitId 7.3.5 OS Microsoft Windows 10.0.22621 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0

SQL Server Edition and Build number

Microsoft SQL Server 2019 (RTM-CU18) (KB5017593) - 15.0.4261.1 (X64) Sep 12 2022 15:07:06 Copyright (C) 2019 Microsoft Corporation Developer Edition (64-bit) on Linux (Ubuntu 20.04.5 LTS) <X64>

.NET Framework Version

.NET 7.0.8

jpomfret avatar Jul 06 '23 12:07 jpomfret