I want to perform some sql when my database mirroring state changes
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
Create an event notification for the Database Mirroring State Change. See Implementing Event Notifications for how to design a service that processes the notification and does whatever is appropriate. Keep in mind that event notifications are asynchronous.
You can do this using SQL Server alerts, which can trigger a job after the WMI event occurs.
Your WMI Query in this case will be
More details (and scripts): http://msdn.microsoft.com/en-us/library/cc966392.aspx