That's what I'm doing now. Unfortunately, the call to the database is taking
too long to timeout (16-18 seconds). I was hoping for a way to speed that up
to 3-5 seconds.

-----Original Message-----
From: Billy Cox [mailto:[EMAIL PROTECTED] 
Sent: Thursday, April 19, 2007 10:50 AM
To: CF-Talk
Subject: RE: Testing Database Connection within Application

You could wrap your database call in a cftry block and then specify code to
run when an error happens.


<cftry>

<cfquery>

</cfquery>

<cfcatch type="database">
        code to run in event of database error (cfmail?)
</cfcatch>

</cftry>



-----Original Message-----
From: Rob O'Brien [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 19, 2007 10:38 AM
To: CF-Talk
Subject: Testing Database Connection within Application


I've done my searching online, throughout several groups, and now I turn to
you guys.



I've been having trouble figuring out how to detect, from within my
ColdFusion application, whether or not my database connection is valid.



The DB setup is valid, but my goal is to automatically detect when the
database server is temporarily down/unavailable in order to display an
automatic "maintenance" message in the case of a crash or true maintenance
when the database is offline.



I've tried to put a simple query into my Application file and use CFQUERY's
Timeout to force a quick (5 second) error within a CFTRY, but I'm inclined
to think that it only has an affect on SQL Server when it's up and running,
but taking too long to return a result. With my current attempt, it's taking
up to 18 seconds to fail, which is just too long. Even using CFSETTING to
set RequestTimeout to a lower value doesn't seem to have an affect.



This was my attempt:



      <CFTRY>

            <CFQUERY datasource="#DBDATASOURCE#" username="#DBUSERNAME#"
password="#DBPASSWORD#" name="testConnection" timeout="5">

                  SELECT TOP 1 THEME_ID FROM TBL_THEME

            </CFQUERY>

      <CFCATCH>

            <!-- DB Connection failed -->

            <cfinclude template="Maint.cfm">

            <CFABORT>

      </CFCATCH>

      </CFTRY>



If it matters, we're using MSSQL now, though we're planning to switch to
MySQL eventually. I know there are timeout differences with CFQUERY's
Timeout in conjunction with different DB drivers and I'd like to come up
with a single, generic solution.



I appreciate any feedback.



Rob







~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Deploy Web Applications Quickly across the enterprise with ColdFusion MX7 & 
Flex 2
Free Trial 
http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJU

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:275862
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to