DBCheck set up by Maint Plan fails on AG non-readable secondary

Claudio Gatto 1 Reputation point
2021-10-26T03:20:05.783+00:00

DBCheck set up by Maint Plan fails on AG non-readable secondary because DBCC CheckDB preceded by "Use <db>". Is that documented anywhere?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,815 questions
{count} votes

1 answer

Sort by: Most helpful
  1. AmeliaGu-MSFT 13,961 Reputation points Microsoft Vendor
    2021-10-26T06:35:31.533+00:00

    Hi ClaudioGatto-2410,
    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.

    Best Regards,
    Amelia


    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.

    0 comments No comments