all groups > sql server programming > june 2007 >
You're in the

sql server programming

group:

sys.Databases (state) = online does not meean ready and accessible?



sys.Databases (state) = online does not meean ready and accessible? NewToSql
6/24/2007 3:10:51 PM
sql server programming: Hi,
a database could have its Sys.Databases(State) = Online, yet, you may not
be able to access it.
for example, if you run : Use databaseName. you may get an error message
such as the database file is not accessible.
The question, is how to determine if a database is not only online but also
"ready, accessible, and usable" that is you can access it, and run
queries...? Is such info available in any system views?
Thanks

Re: sys.Databases (state) = online does not meean ready and accessible? Hilary Cotter
6/25/2007 12:00:00 AM
For a database to be online in SQL Server 2005, it really means the primary
database file(s) is/are online.

You would have to query all database files to check their availabilty to
ensure that the entire database is online. Here is an example.

create database offlinefiles

go

use offlinefiles

go

ALTER DATABASE offlinefiles ADD FILEGroup test

GO

ALTER DATABASE offlinefiles ADD FILE ( NAME = 'test', FILENAME =
'C:\test.ndf' )

TO FILEGROUP [test]

GO

SELECT NAME, PHYSICAL_NAME, is_read_only, state_desc , name

FROM sys.database_files WHERE STATE_DESC<>'ONLINE'

go

ALTER DATABASE offlinefiles MODIFY FILE (NAME = test, OFFLINE )

GO

SELECT NAME, PHYSICAL_NAME, is_read_only, state_desc , name

FROM sys.database_files WHERE STATE_DESC<>'ONLINE'





--
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html

Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
[quoted text, click to view]

Re: sys.Databases (state) = online does not meean ready and accessible? NewToSql
6/25/2007 8:53:39 AM
Thank you Hilary.

[quoted text, click to view]

Re: sys.Databases (state) = online does not meean ready and accessible? newToSql
6/27/2007 6:56:15 PM
What if you cannot do:
Use databaseName;
go
because of one file of the database is online but not ready / usable. Or
that you cannot do
select * from databaseName.sys.database_files
for the same reason

Back to the question: I want to determine if the database is not only
Online, but that it is Ready [for the lack of a better qualifier] that is I
can query it. How can I do that because the Online state in sys.databases is
not an indication that the database is actually Ready?

Thanks again.



[quoted text, click to view]

Re: sys.Databases (state) = online does not meean ready and accessible? newToSql
6/29/2007 12:30:30 PM
In light of the answer from Hilary (thank you Hilary) , here is the question
worded in a different way:
if I do
Use database;
go
I get an error because the database, though online, is not Ready /
Queryable
and
select * from databaseName.sys.database_files
fails for the same / similar reason.

So, How can I determine if a database is not only Online, but that it is
Ready and Queryable ?
I need to do such verification on several databases on one server (and I
have several servers to check )

Thanks again.


[quoted text, click to view]

AddThis Social Bookmark Button