DBCheck set up by Maint Plan fails on AG non-readable secondary because DBCC CheckDB preceded by "Use <db>". Is that documented anywhere?
Welcome to Microsoft Q&A.
Could you please right-click the Maintenance plan->click view history to check the error message?
I do a little test, and I get the following error message:
Executing the query "USE [xxx]
" failed with the following error: "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.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
If you encounter the same error message as mine, it means that the secondary replica is unreadable and the query cannot be accessed, which caused the issue. If so, please set the secondary replica to readable in primary replica:
USE [master] GO ALTER AVAILABILITY GROUP [groupname] MODIFY REPLICA ON N'replicaname' WITH (SECONDARY_ROLE(ALLOW_CONNECTIONS = ALL)) GO
Please refer to this doc which might be helpful.
If you have any question, please feel free to let us know.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
14 people are following this question.