sqlsql-serversql-server-2008-r2windows-server-2008

Check if external database is online


I know that this sentence tells me that 'MyDatabase' database is online:

select databasepropertyex('MyDatabase', 'Status')

What if I need to check a database from another server? Suppose that I already have a link server, the call should be like this:

select databasepropertyex('[192.168.111.33].MyOtherDatabase', 'Status')

but it doesn't work, anyone knows how to check this? Thank you.


Solution

  • Might have to run as a pass through query, e.g.

    OPENQUERY ( [192.168.111.33] ,'select databasepropertyex(MuOtherDatabase, ''Status'')' )
    

    (assuming your already set up linked server is called [192.168.111.33], as implied above - seems like a dubious naming convention to use IPs?)