Here’s some quick sql logic to show you the Servers involved in a database mirror. This does not show you which is Principal or Mirror, but only the server names. The query shows “Server1” and “Server2” plus the “Witness”, but that it. It’s meant to give you the Server names.
use master; set nocount on select [Server1] = @@servername , [Server2] = replace(reverse(right(reverse(mirroring_partner_name), len(mirroring_partner_name) - charindex('.',reverse(mirroring_partner_name),10) + 0)), 'TCP://', '') , [Witness] = case mirroring_witness_name when '' then 'NOT CONFIGURED' else replace(reverse(right(reverse(mirroring_witness_name), len(mirroring_witness_name) - charindex('.',reverse(mirroring_witness_name),10) + 0)), 'TCP://', '') end from master.sys.database_mirroring where mirroring_partner_name is not null
Categories: SQL Stuff