Detect Database is being recovered condition.

  • I have "Live" databases and log shipped databases co-mingled on the same server.

    The log ship state that the log shipped databases are in is normally STAND BY unless they are actively being refreshed with the latest logs.

    I am using the following TSQL.

    IF EXISTS ( SELECT * FROM sys.databases d WHERE d.is_in_standby=0 AND d.is_read_only=0 AND d.state=0 AND d.name = 'MyDB' AND d.state_desc='ONLINE' )

    BEGIN

    Exec (‘USE MyDB:Run some sql’)

    END

    Based on this I would expect that I could bypass all my databases that are being log shipped or are in standby or recovery mode.

    However, using the above TSQL I still intermittently receive the following error:

    Database 'MyDB' is being recovered. Waiting until recovery is finished.

    Is there another way to detect this condition for a database?

    This is a SQL 2k8 database.

    Thanks in advance

    Steve

Viewing 0 posts

You must be logged in to reply to this topic. Login to reply