Posts

Showing posts from March 12, 2019

function to check whether the current server is involved in an availability group and if so, whether it is...

Image
3 1 I used to have 2 servers on an availability group, but there was a problem with one of them servers involved,while patching, and to make a long story short I removed all the databases from the availability group. The way I managed execution of jobs only in the primary server was mainly through this script which tests whether the database is in the primary replica: If sys.fn_hadr_is_primary_replica ('apcore') =1 BEGIN EXEC [APCore].[app].[usp_upd_applicationStatusTimeExpired] END But now that the current server is the only server in the Availability group, this script select sys.fn_hadr_is_primary_replica ('apcore') retuns null, and therefore is not accurate. I have been developing a function that should return a bit 1 in one of the following cases: 1 - we are