dataplat / web

dbatools.io website
1 stars 6 forks source link

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

Open SteveHindle opened 7 months ago

SteveHindle commented 7 months ago

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.

Does anyone know why this may be happening?

Thanks

Steve