Link to home
Start Free TrialLog in
Avatar of b_k_cheah
b_k_cheah

asked on

Prevent ASP timeout

When I process/retrieve huge Records in ASP, I get timeout error message.
I want to prevent Server script timeout and Proxy Server timeout, with posting something to the current page. How to do this ?

I know that I can set the Server.Timeout, but I dont want to use this method. I would like to post something like current process status, at least let user know.

Thanks
Avatar of newjack
newjack


You'll probably have to set the Server.TimeOut variable anyway if you want to avoid the script-timeout message.

One way I implemented a status-bar from ASP was by sending javascript code to the client after a certain interval with the Response.Flush command (otherwise it's just buffered).

This javascript code then updated the content of a DIV-tag, containing the status message.

Avatar of Michel Sakr
if it's huge record your best choice to boost performance is to create stored procedures in SQL instead of sending inline queries.. if its sql.. or try to get onlu the needed fields in your recordsets.. don't select * (all) the fields to return.. also you can encapsulate your code in a component (dll) to retrieve records..
Also you can use paging to split up your record set

http://www.4guysfromrolla.com/webtech/121298-1.shtml

If you don't want to use stored procs. However a combination of paging and stored procs will give you the best advantage

That's all good, but the question here is not how to speed things up, but how to show some sort of status to the user.

Sometimes things just take a long time, and there's nothing you can do about it.
I've had it when I wanted to delete thousands of records using a web interface.  There was no way to speed it up, but a status had to be displayed.



Btw, another solution of a status display could be to use MS Message Queue.  I haven't used it myself, but according to what I've read you can assign your lengthy database statements ot MSMQ and afterwards periodically check that process and check it's state.



Also, if you are doing some heavy processing on a huge amount of records, try to split it up into smaller transactions.
When you do it all in a single transaction, SQL will be creating a huge transaction log and causing a serious performance hit on your site.

If you are delete a large amount of records ie a table worth it might be worth considering to use Truncate table.
This does not go through the logs. To add to what newjack said about samller transactions I normally wrap every delete statement in a transaction if it fails then I either write it to an excepetions log with an email or stop the whole process. Committimg a row at a time means that it reduces log problems
Set the Command.CommandTimeout property to as long a period as you need
Avatar of b_k_cheah

ASKER

Hi NewJack,

I am interesting on your suggestion. Mind to send me the sample script of what you said ?

I will accept it as answer if the script really work. Hope to hear from you very soon.

Cheah
Hi NewJack,
Sorry that I am HTML idiot. I just wondering how you use the Javascript to update your <DIV> tag while you triggering your Response.Flush. Appreciate if you can help me on this area.

Thanks.
Hi NewJack,
Sorry that I am HTML idiot. I just wondering how you use the Javascript to update your <DIV> tag while you triggering your Response.Flush. Appreciate if you can help me on this area.

Thanks.
Hi New Jack,
Please send me the Javascript and HTML sample code.

Thanks
There are a couple of things that you need to consider here.

Firstly no matter what techniques you might use to display an ongoing statuts you still have a finite window in which the transaction must be completed. Even altering the server timeouts won't do the whole job as there are time outs on the client as well. (5 minutes is the rule of thumb in that you can't reliabily exceed this).

Secondly if you are retrieving vast amounts of data and sending them to the client then you will start having problems with the client running out of memory.

The trick is to break the processing down into lumps. Where you are displaying the data then the best bet is a more/next type option.

If it is deletions,inserts or updates then you need to break this down into chunks as well.

For example a mass deletion can be achieved in the following steps

1 Generate and store the SQL to do the deletions.
2 Do 100 (say) deletions
3 Send back a page that says 'processing' with an immediate redirection to the 2nd processing page
4 The second processing page retireves the SQL and repeats the process from 2 until all the records are processed whereby it sends a different page.

Hope that helps
Steve
ASKER CERTIFIED SOLUTION
Avatar of newjack
newjack

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Increase your connection command timout like:

Connection.CommandTimeout = 1200 (20 minutes)

this should be done directly after defining the connection and before opening it

also you can put a note before for the client that the page might take several minutes to load.. also don't forget to increase the script timeout at the beginning to exceed the command timeout
server.scripttimeout = 1200


nevertheless you should also try to enhance the performance of your queries and tables..

rgrds


Thanks for your help. In fact, it is easy to learn and understand. With the response.flush, it solved the most important issue, Proxy Server Connection timeout. But, The IIS script timeout not ! Actually before that, I had know response.flush method, but donno how to use it. Thanks for give me an idea, Thanks for the sample script. I believe the end user will like the progess status bar or text. But the disadvantage is, it keep generate the long HTML script.

That's all. Thanks.