Dofs
Dofs

Reputation: 19227

Check for active connection in NHibernate

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

Answers (1)

gbn
gbn

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

Related Questions