I've set up alerts on my SQL server to alert me when the mirroring state of any of my mirrored databases changes, as per this article.

It's all working fine but I was wondering if there was any way, via T-SQL, to get the description of a database mirroring state from the state ID provided by $(WMI(State)) ?

The article I linked to provides a list of all the possible states and what they mean, so I could create my own table or use a CASE statement, but it would be nice if I could use built-in function or select from an existing table. Maybe my Google-Power is low today, but I've not been able to find anything.

有帮助吗?

解决方案

To do this I ended up adding a CASE statement to my script - I could have created a table but this is more portable as I wanted to copy the script to several different servers.

declare @MirrorStateDesc varchar(50)
select @MirrorStateDesc = '$(ESCAPE_NONE(WMI(State)))'
select @MirrorStateDesc = CASE @MirrorStateDesc WHEN '7' THEN 'Manual Failover' WHEN '8' THEN 'Automatic Failover' WHEN '10' THEN 'No Quorum' WHEN '12' THEN 'Principle Running Exposed' ELSE @MirrorStateDesc  END

I'm only using this script on states 7, 8, 10 and 12 so they are the only ones I added to my case statement. The other values and descriptions are on the page I linked to in the question, if anybody wants to expand the script for their own uses.

I'm still surprised that there isn't a built in function to do this though!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top