Microsoft KB Archive/261211

= How To Execute Long Running Queries from Active Server Pages =

Article ID: 261211

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Active Server Pages 4.0

-



This article was previously published under Q261211



SUMMARY
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.



MORE INFORMATION
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.

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 &quot;Please Wait .... &quot; Response.Flush

Server.ScriptTimeout = 3600

Set oConn = Server.CreateObject(&quot;ADODB.Connection&quot;)

oConn.Open(&quot;Provider=SQLOLEDB.1;Initial Catalog=Northwind;Data Source=;User ID=;Password=&quot;) Set oRs = Server.CreateObject(&quot;ADODB.Recordset&quot;) Set oCmd = Server.CreateObject(&quot;ADODB.Command&quot;)

oCmd.ActiveConnection = oConn oCmd.CommandTimeout = 3600 oCmd.CommandText = &quot;TestWait&quot; oCmd.CommandType = adCmdStoredProc

Set oRs = oCmd.Execute

Do While Not oRs.EOF Response.Write( &quot;Value From Recordset = &quot; & oRs(1) & &quot;&quot;) oRs.MoveNext Loop

oConn.Close

Set oRs = Nothing Set oConn = Nothing %>

Keywords: kbhowto kbcodesnippet KB261211

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.