How To Simulate Long-Running SQL Calls from ASP (247380)



The information in this article applies to:

  • Microsoft Active Server Pages
  • Microsoft Data Access Components 1.5
  • Microsoft Data Access Components 2.0
  • Microsoft Data Access Components 2.1
  • Microsoft Data Access Components 2.5
  • Microsoft Data Access Components 2.6

This article was previously published under Q247380

SUMMARY

This articles demonstrates how to simulate long-running stored procedures from Active Server Pages (ASP) pages. You can use this sample to test connection timeouts and long-running queries.

MORE INFORMATION

  1. In a blank ASP file, copy the following code:
    <%
     	Dim cnn, cmd, pa
      
        	Set cnn = server.createobject("ADODB.Connection")
    	set cmd = server.createobject("ADODB.Command")
    
             'This assumes you have already created a PUBS DSN
        	cnn.ConnectionString = "dsn=pubs"    
         	cnn.Open
    
    	'TestDelay is the name of the Stored Procedure	
    	cmd.CommandText = "{? = Call TestDelay (?) }"
    
    	Set cmd.ActiveConnection = cnn
    	cmd.parameters.refresh
    	
    	'Setting the delay to 5 seconds, the format is HH:MM:SS	
    	cmd(1) = "0:00:05"
    	response.write Now & "<BR>"
    	response.flush
    
    	set rs = cmd.Execute
    
    	response.write rs(0)
    
    	Set cmd.ActiveConnection = Nothing
    	Set cmd = nothing
    	set cnn = nothing
    	set rs = nothing
    %>
    					
  2. Create this stored procedure in your PUBS database:
    CREATE PROC TestDelay
    @@DelayLength CHAR(9)
    AS
    BEGIN
       WAITFOR DELAY @@DelayLength
       SELECT GetDate()
    END
    					
  3. Run and test your ASP file.

Modification Type:MinorLast Reviewed:7/13/2004
Keywords:kbhowto kbSQLProg KB247380