Connect to DB Mirror Failover Partner

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 11 months ago.

  • Author
    Posts
  • #6379

    by mg48 at 2013-01-31 12:10:38

    How does Powershell handle connecting to a mirrored failover partner automatically as it will in a .Net program that specifies the failover partner in the connection string?

    by Klaas at 2013-02-01 00:28:02

    I think you should check the status of the databases, the principal will have status 'normal', the mirror is 'restoring'. Of course there's a possibility neither is available.
    If ((Get-Childitem SQLSERVER:SQL\server1\instance1\databases | Where { $_.name -LIKE 'mirroreddbname'}).status -eq 'Normal') { $instance = "server1\instance1" }
    ElseIf ((Get-Childitem SQLSERVER:SQL\server2\instance2\databases | Where { $_.name -LIKE 'mirroreddbname'}).status -eq 'Normal') { $instance = "server2\instance2" }
    Else { "None of the instances is available" }
    You can do pretty much the same with SMO instead of the SQL Provider.

    It 's probably even better to check the availability of the server first, to catch any case where the principal is unavailable for other reasons than a failover.

You must be logged in to reply to this topic.