Reputation: 19227
I have a system with a few different databases, and I would like to check if a certain database is down, and if so display a message to the user.
Is it possible in NHibernate to check if there is an active connection to the database, without having to request data and then catch the exception?
Upvotes: 1
Views: 1093
Reputation: 432311
Query the state
column of sys.databases
ONLINE = OK, anything else = not available
SELECT state FROM master.sys.databases WHERE [name] = 'MyDB'
or
SELECT COUNT(*) FROM master.sys.databases WHERE [name] = 'MyDB' AND state = 'ONLINE'
Upvotes: 2