Link to home
Start Free TrialLog in
Avatar of wasabi3689
wasabi3689Flag for United States of America

asked on

how to do this script?

I have a always-on databases, I want to have a script to do

When the always-on availability  group failover is successful from primary to secondary, run this stored procedure. If not successful, do nothing. how to do that? I want to do that in an agent job or something, when the failover happened, automatically kick off this job. My always SQL is 2016 enterprise
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Problem is that SQL Agent jobs aren't triggered by actions so you can't really have this kind of solution.
You may have a SQL Agent job that runs every minute to check if the Primary Replica changed and then execute something when this validation is true.
Avatar of wasabi3689

ASKER

how to do that? how to check every minute in scripting?
Well, you'll need to store last status in a table and then compare it with the actual status. When differs then perform what you want to perform.
need more detail coding you have before
No code. I'm giving you an high-level solution.
ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Solution provided.