Symptoms

Assume that you use an Always On high availability group (AG) as a secondary replica. When you try to upgrade Microsoft SQL Server 2016 to Service Pack 2 (SP2) Cumulative Update 11 (CU11) or later versions, the upgrade script fails, and you may receive the following error messages:

DateTime spidSpidId      Upgrading subscription settings and system objects in database [DatabaseName].

DateTime spidSpidId      Failed to update database "DatabaseName" because the database is read-only.

DateTime spidSpidId      Error executing sp_vupgrade_replication.

Cause

When an upgrade is performed on the secondary replica of a SQL AG, there is a race between the database recovery and the upgrade script execution. Therefore, the cursor that you use inside sp_vupgrade_replication cannot filter out the read-only databases correctly. For a short time, the secondary databases in recovery phase are included in the list of editable database. Therefore, when you try to update these databases, an exception is returned because the databases are read-only.

Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

Resolution

This issue is fixed in the following cumulative updates for SQL Server:

About cumulative updates for SQL Server:

Each new cumulative update for SQL Server contains all the hotfixes and all the security fixes that were included with the previous cumulative update. Check out the latest cumulative updates for SQL Server:

References

Learn about the terminology that Microsoft uses to describe software updates.

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.