Sunday, March 25, 2012

Determine if database is in standby/read-only mode?

Hi all,
Sorry for the frequent posts, but I have one other thing I'd like to figure
out.
Can I write a query to determine if a database is in standby or read-only
mode? I would like to put a check in the restore routine for custom log
shipping so that DIFFs and TRANS are restored when not in standby/read-only.
I tried to trace Enterprise Mangler, and see how it set the Read-only
checkbox for the database properties, and I saw this ...
USE [<DatabaseName>]
SELECT FILEGROUPPROPERTY( f.groupname, N'IsReadOnly' ) FROM
dbo.sysfilegroups f
However, even though Enterprise Mangler shows read-only as checked, this
query keeps returning false (0).
Any thoughts? Am I going about this the wrong way?
Thanks for the help!
WadeNevermind, I found it:
use [master]
select name, DATABASEPROPERTY(name, N'IsReadOnly') from
master.dbo.sysdatabases
Thanks!
"Wade" <wwegner23NOEMAILhotmail.com> wrote in message
news:%23ZxMnTZrFHA.1128@.TK2MSFTNGP11.phx.gbl...
> Hi all,
> Sorry for the frequent posts, but I have one other thing I'd like to
> figure out.
> Can I write a query to determine if a database is in standby or read-only
> mode? I would like to put a check in the restore routine for custom log
> shipping so that DIFFs and TRANS are restored when not in
> standby/read-only.
> I tried to trace Enterprise Mangler, and see how it set the Read-only
> checkbox for the database properties, and I saw this ...
> USE [<DatabaseName>]
> SELECT FILEGROUPPROPERTY( f.groupname, N'IsReadOnly' ) FROM
> dbo.sysfilegroups f
> However, even though Enterprise Mangler shows read-only as checked, this
> query keeps returning false (0).
> Any thoughts? Am I going about this the wrong way?
> Thanks for the help!
> Wade
>|||Use function databaseproperty.
Example:
use master
go
select
[name],
databaseproperty([name], 'IsInStandBy') as IsInStandBy,
databaseproperty([name], 'IsInRecovery') as IsInRecovery
from
sysdatabases
go
AMB
"Wade" wrote:
> Hi all,
> Sorry for the frequent posts, but I have one other thing I'd like to figure
> out.
> Can I write a query to determine if a database is in standby or read-only
> mode? I would like to put a check in the restore routine for custom log
> shipping so that DIFFs and TRANS are restored when not in standby/read-only.
> I tried to trace Enterprise Mangler, and see how it set the Read-only
> checkbox for the database properties, and I saw this ...
> USE [<DatabaseName>]
> SELECT FILEGROUPPROPERTY( f.groupname, N'IsReadOnly' ) FROM
> dbo.sysfilegroups f
> However, even though Enterprise Mangler shows read-only as checked, this
> query keeps returning false (0).
> Any thoughts? Am I going about this the wrong way?
> Thanks for the help!
> Wade
>
>|||See DATABASEPROPERTY and DATABASEPROPERTYEX functions in SQL Server Books
Online.
--
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Wade" <wwegner23NOEMAILhotmail.com> wrote in message
news:%23ZxMnTZrFHA.1128@.TK2MSFTNGP11.phx.gbl...
> Hi all,
> Sorry for the frequent posts, but I have one other thing I'd like to
figure
> out.
> Can I write a query to determine if a database is in standby or read-only
> mode? I would like to put a check in the restore routine for custom log
> shipping so that DIFFs and TRANS are restored when not in
standby/read-only.
> I tried to trace Enterprise Mangler, and see how it set the Read-only
> checkbox for the database properties, and I saw this ...
> USE [<DatabaseName>]
> SELECT FILEGROUPPROPERTY( f.groupname, N'IsReadOnly' ) FROM
> dbo.sysfilegroups f
> However, even though Enterprise Mangler shows read-only as checked, this
> query keeps returning false (0).
> Any thoughts? Am I going about this the wrong way?
> Thanks for the help!
> Wade
>

No comments:

Post a Comment