views:

32

answers:

2

I have to include one report in my application showing offline/online activity of few databases on SQL Server 2008. Could you please suggest how can I collect teh same information from sql server?

+2  A: 

SELECT DATABASEPROPERTYEX('YOURDATABASE', 'Status') DatabaseStatus_DATABASEPROPERTYEX GO

SELECT state_desc DatabaseStatus_sysDatabase FROM sys.databases WHERE name = 'YOURDATABASE' GO

This will tell you the status of the database.

Ardman
Using these queries I can find out if the database is offline/online at present. However, I am looking for a way to know the time when the database went online /offline last time.
+2  A: 

In order to find out when your database was taken OFFLINE, you can use the SQL that I posted before, or the easiest way is to check the Event Viewer and it will tell you when the Database was taken OFFLINE. I have just tested this on my local machine and SQL Server writes out an Information message to the Application log.

Ardman
Thanks ardman.Event Viewer option works for me.