Skip to main content
Jush1
Known Participant
April 28, 2011
Answered

Warning before cfquery timeout

  • April 28, 2011
  • 2 replies
  • 3824 views

When your cfquery takes longer than the timeout time set in CFAdmin or CFSetting, you will get a error message saying:

The request has exceeded the allowable time limit Tag


Which is what I don't want user to see. So before it comes up, is there here anyway I could warn the user, the query takes too long to process, please refine you filter?

For instance, if the CFAdmin/CFsetting sets timeout 120 seconds, so right before the message came up, maybe at 115 seconds, trigger a warning and send the user back to the form page.

Or what should be the best way to handle cf query timeout errors if I don't want to make timeout time any longer?

Thanks for you help in advance.

This topic has been closed for replies.
Correct answer ilssac

Thanks for the explanation. Actually I am trying to do it in this way:

first set variable queryExecTime = queryName.getMetaData().getExtendedMetaData().executionTime


then I check if queryExecTime gt 100, I pop the message and send the user back. This way, prevented the long time message shows up.

There is a catch though, when the query is cached, ( the cfquery set cacheWithin 30 minutes), queryExecTime is 0, it it will not trigger the pop up. Not sure if there is goiing to be a problem.


Jush wrote:

Not sure if there is goiing to be a problem.

I don't see how using the cached data would cause a problem.  By definition, cached data is returned instantly, because the database IS NOT queried during the cached time period.  So your time out code should only come into effect when the cached data has expired and the database is running the query again.

BUT if you are using cached data, maybe you don't need all this problem anyway.  Instead of having one user wait on the query and then let all the other users get instant results for the next 30 minutes.  Return the cached data to all users, then every thirty minutes let the query run in the background to refresh the cached data.  There are also several ways this could be accomplished.

2 replies

Inspiring
April 28, 2011

Look at the search parameters before the query starts.  If they look like they will cause a timeout, display your message then.

Jush1
Jush1Author
Known Participant
April 28, 2011

Thanks Dan, that is what I am doing, There is a "Select All" button, which is usually the cause of the problem, So that is where trigger the message. And if it happens matter because of Select All or not, it took longer then 120, it will get an explanation message as well.

ilssac
Inspiring
April 28, 2011

There's nothing you can do to interecept the time out at 115 seconds AFAIK.

What you CAN do.

You would wrap the <cfquery...> block in a <cftry>...<cfcatch...></cftry> block.  This would allow you to provide any message you cared to, instead of the default ColdFusion message.

Jush1
Jush1Author
Known Participant
April 28, 2011

But that try and catch message is going to be shown after 120 seconds, right?  Besides my environment policy does not allow me to use cftry and cfcatch. That is the problem. Thanks for your response Ilssac.

ilssac
Inspiring
April 28, 2011

Jush wrote:

But that try and catch message is going to be shown after 120 seconds, right? 

Yes, actually it can be longer, because ColdFusion can not do anything to stop the database.  So, CF may wait until the database finishes, however long that takes, and then return the too long message.

Jush wrote:

Besides my environment policy does not allow me to use cftry and cfcatch. That is the problem.

That is a very unusual policy!  I usually hear of policies to be the other way.  Why would there be a policy to reduce the security and protection of an application.