Troubleshooting Guide: Error 7877 – Backup on Secondary Replica Not Supported in Contained Availability Group
Why This Error Happens
This error occurs because the client connection string is routing the backup operation to a secondary replica without properly specifying the contained availability group name in the connection context, causing SQL Server to reject the request since it cannot resolve the correct read-only routing or backup preference. It commonly happens when applications or backup tools use a direct server name or listener that does not explicitly reference the contained AG’s name property, which is required in SQL Server 2025’s contained availability group architecture. Additionally, a stale or cached connection to the instance may retain outdated metadata about the AG topology, preventing the backup preference settings from being honored correctly.
Step-by-Step Resolution Guide
Step 1: Verify the Backup Preference Settings on the Availability Group
- Open SQL Server Management Studio (SSMS) and connect to the primary replica.
- Run the following query to check current backup preferences:
SELECT ag.name, ag.automated_backup_preference_desc
FROM sys.availability_groups ag;
- Confirm whether the preference is set to “Secondary only,” “Prefer Secondary,” “Primary,” or “Any,” and ensure this aligns with your intended backup strategy.
Step 2: Update the Connection String to Reference the Contained AG Name
- Ensure your backup script or third-party backup tool explicitly uses the contained availability group’s listener name or AG name, not just the instance name.
- Example connection string correction:
Server=AGListenerName;Database=ContainedAGName;Integrated Security=True;
- If using PowerShell or
sqlcmd, confirm the-Sparameter points to the listener, not a standalone node name.
Step 3: Reconnect to the SQL Instance and Clear Cached Sessions
- Fully disconnect all active sessions in SSMS or your backup application (close and reopen the tool rather than just refreshing).
- On Windows Server 2025, restart the SQL Server service if the issue persists:
Restart-Service -Name 'MSSQLSERVER' -Force
- Re-establish the connection explicitly targeting the contained AG, then retry the backup job.
Step 4: Validate Contained AG Metadata Synchronization
- Run
DBCC CHECKDBandsys.dm_hadr_availability_group_stateson the secondary replica to confirm synchronization health. - Check for replication latency or metadata mismatch errors in the SQL Server Error Log located at:
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG
- If metadata is out of sync, failover to the primary temporarily and re-sync the secondary.
Alternative or Verification Steps
- To verify the fix, manually initiate a
BACKUP DATABASEcommand targeting the secondary replica withWITH COPY_ONLYand confirm it completes without throwing Error 7877. - If the issue persists, as a workaround, redirect backups temporarily to the primary replica by adjusting the AG’s
automated_backup_preferenceto “Primary” until the contained AG connection metadata issue is fully resolved.