You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Within the stored procedure there is a check to see if a database is part of an Always On availability group so that it doesn't execute on a read only secondary replica.
IF exists (select *
from sys.databases databases
INNER JOIN sys.availability_databases_cluster adc
ON databases.group_database_id = adc.group_database_id
INNER JOIN sys.availability_groups ag
ON adc.group_id = ag.group_id
WHERE databases.name = DB_NAME() )
begin
declare @replicaStatus int;
select @replicaStatus = sys.fn_hadr_is_primary_replica ( DB_NAME() );
SELECT @replicaStatus
if @replicaStatus <> 1
begin
BEGIN
SELECT 'Secondary Replica'
end
end
return;
end
This check is failing and stopping the rest of the procedure from running, even when the database is on a primary replica. I believe this is due to the IS NOT NULL check on the @replicaStatus, if this is removed it should then work.
IF exists (select *
from sys.databases databases
INNER JOIN sys.availability_databases_cluster adc
ON databases.group_database_id = adc.group_database_id
INNER JOIN sys.availability_groups ag
ON adc.group_id = ag.group_id
WHERE databases.name = DB_NAME() )
begin
declare @replicaStatus int;
select @replicaStatus = sys.fn_hadr_is_primary_replica ( DB_NAME() );
SELECT @replicaStatus
if @replicaStatus <> 1
begin
BEGIN
SELECT 'Secondary Replica'
end
end
return;
end
The text was updated successfully, but these errors were encountered:
Also the return needs to be move into the begin...end block
IF exists (select *
from sys.databases databases
INNER JOIN sys.availability_databases_cluster adc
ON databases.group_database_id = adc.group_database_id
INNER JOIN sys.availability_groups ag
ON adc.group_id = ag.group_id
WHERE databases.name = DB_NAME() )
begin
declare @replicaStatus int;
select @replicaStatus = sys.fn_hadr_is_primary_replica ( DB_NAME() );
SELECT @replicaStatus
if @replicaStatus <> 1
begin
BEGIN
SELECT 'Secondary Replica'
END
return;
end
END
SELECT 'primary'
Within the stored procedure there is a check to see if a database is part of an Always On availability group so that it doesn't execute on a read only secondary replica.
This check is failing and stopping the rest of the procedure from running, even when the database is on a primary replica. I believe this is due to the IS NOT NULL check on the @replicaStatus, if this is removed it should then work.
The text was updated successfully, but these errors were encountered: