Quantcast
Channel: SQL Server High Availability and Disaster Recovery forum
Viewing all articles
Browse latest Browse all 4689

Jobs in SQL Always on

$
0
0

I am using SQL 2012 with Always on (with automatic fail over); I have few jobs. I understand that I can use following logic to determine if the present node is primary or replica.

DECLARE@ServerName NVARCHAR(256) =@@SERVERNAME

DECLARE@RoleDesc NVARCHAR(60)

SELECT@RoleDesc= a.role_desc

   FROM sys.dm_hadr_availability_replica_statesAS a

   JOIN sys.availability_replicasAS b

       ON b.replica_id= a.replica_id

WHERE b.replica_server_name=@ServerName

IF@RoleDesc='PRIMARY'

BEGIN

   --Logic for the job goes here

END

 

Now I have several steps on my job. Basically I want to determine the role of the server (i.e. primary or replica)on the step 1 of the job  and if it is primary then job will go to the next step otherwise job will ended without moving to next step. How can I achieve it?

Thanks 


Viewing all articles
Browse latest Browse all 4689

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>