snapshot isolation error using sp_setapprole on a read-only Availability Group replica

455 Views Asked by At

I am investigating SQL Server Always On Availability Groups and ran into a problem when setting an application role on the read-only replica database. What really irritates me is the behavior, and I don't know how to interpret the error message.

All I do is call

DECLARE @cookie varbinary(8000);

EXEC sys.sp_setapprole
    @rolename = 'TestRole', -- sysname
    @password = 'password', -- sysname
    @fCreateCookie = 1, -- bit
    @cookie = @cookie OUTPUT; -- varbinary(8000)

EXEC sys.sp_unsetapprole @cookie = @cookie; -- varbinary(8000)

which works fine for the first attempt. On the second and all following tries, I receive the following error:

Msg 3961, Level 16, State 1, Procedure sp_setapprole, Line 44 [Batch Start Line 25] Snapshot isolation transaction failed in database 'AGTest' because the object accessed by the statement has been modified by a DDL statement in another concurrent transaction since the start of this transaction. It is disallowed because the metadata is not versioned. A concurrent update to metadata can lead to inconsistency if mixed with snapshot isolation.

When I execute the same statement on the primary database, I can set the approle on the replica again - once.

I tested different isolation level settings (although I wouldn't be willing to change it for the later productive database), which didn't work. I currently have no further approach to the problem, and google has almost no info for me.

1

There are 1 best solutions below

0
On

Just to sum this up (for those who may run into similar problems): It was a SQL Server bug, which was fixed by Microsoft after I filed a support request (SP2 CU4). Unfortunately the fix seems to be available for SQL Server 2016 only, 2017 didn't inherit it - I hope it will be part of 2019, else I will have to create a new support case.

https://support.microsoft.com/en-us/help/4469908/error-3961-when-you-use-application-roles-read-only-secondary-replicas