Checking DB aliveness

Checking DB aliveness

Old forum URL: forums.lhotka.net/forums/t/725.aspx


Michael Hildner posted on Tuesday, July 25, 2006

Hello,

Is there a CSLA-compliant way to check if the database is accessible?

I need to poll and make sure that the database is currently up. Would like to make sure that whatever I do fits in with CSLA. My initial thought is to have a read only root, probably with a single property, that might return GETDATE() or similar. If Fetch fails, I'll know that the DB is not available at that time.

I realize of course (as does the client), that this is no guarantee that the network/db will be up and running immediately after, but it's a requirement.

Thanks,

Mike

ajj3085 replied on Wednesday, July 26, 2006

Yes, I do this currently in my application.

You do this the same way you would anything; write a use case and start from there.  That will guide you with a 'business object' that has the functionality.  Instead of Save though you may want to have a Check() method (which could just call save, much like calling Close on a DataReader just calls Dispose behind the scenes). 

Alternately, you can just create a static class which a factory method, the result returns either an instance you can query, or a simple boolean (depending on what you want to do).

HTH
Andy

RockfordLhotka replied on Wednesday, July 26, 2006

Yes Mike, your answer is a good one. But Andy is right too - this should be a logical part of your object model based on a "See if database is available" use case.

So while I too would use a ROB-derived object, I'd make sure to name it and its factory method appropriately so it is very clear what it is doing:

If DataBase.IsAvailable Then

or something like that. Your factory method doesn't have to return the object - it can just return a boolean.

Copyright (c) Marimer LLC