views:

24

answers:

1

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?

+1  A: 

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'
gbn
Okay so I need to create that query, NHibernate doesn't have anything buildt in?
Dofs
Not that I know of... you're asking for something that is SQL Server and DB specific rather that mapping an ORM
gbn
Can't you just query the state of ISession.Connection?
Berryl
@Berryl: this won't tell you if a particular DB is available
gbn
I am sorry if I was unclear, but I just needed to check if the session was available without having to catch an exception.
Dofs
@Dofs, @Berryl: ah OK. I worked on the "...certain database is down..." bit
gbn