Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 261211 - Last Review: July 1, 2004 - Revision: 1.1
How To Execute Long Running Queries from Active Server Pages
This article was previously published under Q261211
Running a stored procedure or a query that takes a long time to run from Active Server Pages (ASP) may cause the browser and/or ASP page to timeout out before the stored procedure finishes running. Microsoft recommends that you NOT run such procedures from ASP, but it might be unavoidable.
You must set a number of timeout values to allow the execution of the stored procedure to complete. The values you use should be based on the estimated time it should take the stored procedure to run.
Collapse this tableExpand this table
| Timeout Value | Description |
|---|
| Server.ScriptTimeout = NumSeconds | This value determines how long a script should run before it is terminated. |
| (Command Object).CommandTimeOut = NumSeconds | This value indicates how long to wait for a command that is running before it terminates. |
Additionally, use the following statement to prevent the browser from timing out:
<% response.buffer = true %>
The code sets up a persistent HTTP connection by sending a Keep-Alive header to the client. This keeps the TCP/IP connection open between the client and server.
The following code sample demonstrates how to set the timeout values:
<%
Response.Buffer = True
Response.Write "<H1>Please Wait .... </H1>"
Response.Flush
Server.ScriptTimeout = 3600
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open("Provider=SQLOLEDB.1;Initial Catalog=Northwind;Data Source=<ServerName>;User ID=<UserName>;Password=<Password>")
Set oRs = Server.CreateObject("ADODB.Recordset")
Set oCmd = Server.CreateObject("ADODB.Command")
oCmd.ActiveConnection = oConn
oCmd.CommandTimeout = 3600
oCmd.CommandText = "TestWait"
oCmd.CommandType = adCmdStoredProc
Set oRs = oCmd.Execute()
Do While Not oRs.EOF
Response.Write( "Value From Recordset = " & oRs(1) & "<BR>")
oRs.MoveNext
Loop
oConn.Close
Set oRs = Nothing
Set oConn = Nothing
%>
APPLIES TO
- Microsoft Active Server Pages 4.0
| kbcodesnippet kbhowto KB261211 |
Retired KB Content DisclaimerThis article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate