Sample Header Ad - 728x90

Write-DbaDbTableData - "Exception occurred while trying to enumerate the collection" error

0 votes
0 answers
89 views
I have the following code that I use to retrieve some TempDB space details on an AG:
$DataDriveTable = Invoke-DbaQuery -SqlInstance $SQLInstance -Database TempDB -Query $SelectDriveQuery -EnableException

$DataDriveTable | ConvertTo-DbaDataTable | Write-DbaDataTable -SqlInstance $SQLInstance -Database master -Table "TempDBDriveInfo" -EnableException
I started to receive this intermittent error: The following exception occurred while trying to enumerate the collection: > The target database, 'XXX', is participating in an availability group and is currently not accessible for queries. Either data movement is suspended or the availability replica is not enabled for read access. To allow read-only access to this and other databases in the availability group, enable read access to one or more secondary availability replicas in the group. For more information, see the ALTER AVAILABILITY GROUP statement in SQL Server Books Online." I can't understand why it is reading other user databases in the AG as I either specify TempDB or master only? I don't touch user databases or their properties. I have since disabled the job from running if the current node is passive (as it is set to non readable) but would like to understand why the code does this. I expected data to be written to the table but instead received an enumeration error. This only happens on the passive node where users databases are not readable.
Asked by Steve Hindle (1 rep)
Apr 8, 2024, 11:47 PM
Last activity: Apr 12, 2024, 07:10 AM