SELECT ar.secondary_role_allow_connections_desc
FROM sys.availability_replicas AS ar
JOIN sys.availability_databases_cluster adc ON adc.group_id = ar.group_id
WHERE ar.secondary_role_allow_connections > 0
AND adc.database_name = '<<database>>'
AND ar.replica_server_name = @@SERVERNAME
AND sys.fn_hadr_is_primary_replica('<<database>>') = 0
我认为当给定的数据库和当前服务器不是主服务器并且是可读的时,以下查询会返回一行。