Question

Our C# application needs to connect to SQL 2005 and 2008 databases and check what the current status of database mirroring is (eg. is it enabled, suspended, paused, disconnected etc). Are there properties where I can check this?

All our databases that are being mirrored have no witness and manual failover (synchronous mirroring).

Much appreciated if anyone can help out or point me to some documentation, google searches are not turning up much on this.

Was it helpful?

Solution

Current state is shown in sys.database_mirroring:

SELECT mirroring_state 
FROM sys.database_mirroring
WHERE database_id = DB_ID('...');

OTHER TIPS

The MSDN Article here describes all the System Stored procedures that will give you the information you need

You can also retrieve or update the current status by running the sp_dbmmonitorresults system stored procedure.

One non-obvious difference between using the sp_dbmmonitorresults and using sys.database_mirroring table that's in Remus's answer is the permissions required

Rights needed for sys.database_mirroring

According to the MSDN article Remus referenced

To see the row for a database other than master or tempdb, you must either be the database owner or have at least ALTER ANY DATABASE or VIEW ANY DATABASE server-level permission or CREATE DATABASE permission in the master database. To see non-NULL values on a mirror database, you must be a member of the sysadmin fixed server role

Rights needed for sp_dbmmonitorresults

According to the previous mentioned MSDN article on mirroring SP's

members of the sysadmin fixed server role, and users who have been added to the dbm_monitor fixed database role

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top