Mirroring databases connected through a View

Answered Mirroring databases connected through a View

  • Thursday, October 12, 2006 3:03 PM
     
     

    I have two databases db_A_primary and db_B_primary, both databases are on one Primary server.

    db_B_primary has a View into db_A_primary.

    Scenario: db_A_primary goes down and failsover to db_A_mirror on the Mirror server.

    In this scenario when the View in db_B_primary is accessed will it automatically be redirected to look at the db_A_mirror database on the Mirror server?

    Barry.

All Replies

  • Friday, October 13, 2006 3:46 PM
     
     Answered

    When the database fails over, it won't change the contents of the database. If you want the view to always point to a specific server.database.owner.table, you will want to specify it that way in the application. In other cases, you might want the view to point to a local table and wouldn't want to point to a remote server after failover. The bottom line is that it is up to the application to set the behavior desired.

    Regards,

    Matt Hollingsworth

    Sr. Program Manager

    Microsoft SQL Server

  • Wednesday, October 25, 2006 11:32 PM
     
     

    Your mirrored database can not have a different name from the principal database. Perhaps you meant Server Name?

    You can't do this with a view, but in stored procedures, you can use a try/catch to execute a dynamic query on the live server.

    Begin Try

    Exec sp_executesql N'Select * From db_A_primary.dbo.ATable'

    End Try

    Begin Catch

    Exec sp_executesql N'Select * From MirrorServer.db_A_primary.dbo.ATable'

    End Catch