Solved

Prevent ASP timeout

Posted on 2001-08-17
14
613 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:b_k_cheah
  • 5
  • 3
  • 2
  • +3
14 Comments
 
LVL 3

Expert Comment

by:newjack
Comment Utility

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.

0
 
LVL 20

Expert Comment

by:Silvers5
Comment Utility
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..
0
 
LVL 1

Expert Comment

by:deestuar
Comment Utility
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
0
 
LVL 3

Expert Comment

by:newjack
Comment Utility

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.

0
 
LVL 1

Expert Comment

by:deestuar
Comment Utility
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
0
 
LVL 11

Expert Comment

by:jekl2000
Comment Utility
Set the Command.CommandTimeout property to as long a period as you need
0
 

Author Comment

by:b_k_cheah
Comment Utility
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
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:b_k_cheah
Comment Utility
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.
0
 

Author Comment

by:b_k_cheah
Comment Utility
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.
0
 

Author Comment

by:b_k_cheah
Comment Utility
Hi New Jack,
Please send me the Javascript and HTML sample code.

Thanks
0
 
LVL 11

Expert Comment

by:mouatts
Comment Utility
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
0
 
LVL 3

Accepted Solution

by:
newjack earned 250 total points
Comment Utility

Let's say you have this HTML code to define your DIV-tag:

<DIV id="DivMessage"></DIV>

the JavaScript code needed to change the value of this DIV-tag to display "1%" (in bold) would be like this:

<SCRIPT language="JavaScript">

DivMessage.innerHTML = "<B>1%</B>"

</SCRIPT>

You ASP code could look like this:

<%

Do While Not ADORecordSet.EOF
  DoSomething
 
  Response.Write "<SCRIPT language=""JavaScript"">"
  Response.Write "DivMessage.innerHTML = ""<B>1%</B>"""
  Response.Write "<SCRIPT>"

  Response.Flush

Loop

%>

A few comments:

1. make sure that before using this loop you have already flushed your HTML document content to the client (everything between the <HTML>-tags)
2. Use the Response.IsClientConnected property to check if the client is still connected, and if it's necessary to send HTML to the client, or perhaps abort the operation.

Also, you don't have to worry about your client timing out on you as long as you send some code to it on regular intervals.


hope this helps,
NJ
0
 
LVL 20

Expert Comment

by:Silvers5
Comment Utility
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


0
 

Author Comment

by:b_k_cheah
Comment Utility
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.

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now