Fake progress bar whilst Stored Procedure runs using ASP

Discussion in 'ASP General' started by Dooza, Jul 15, 2008.

  1. Dooza

    Dooza Guest

    I have a stored procedure that needs to be executed via an ASP page.

    The SP does a number of tasks, mainly comparing a local table against a
    linked server table, and updating/inserting/deleting where necessary. It
    does this on 4 tables, one of them being fairly large, which will keep
    on growing.

    I have constructed the ASP page, made an animated GIF for the fake
    progress bar, and then inserted the command to run the SP.

    I then check the return value and if its 0 the page is redirected to a
    results page which shows a table.

    When I run this page I don't get to see the animated gif, the page
    pauses until the SP is complete and redirects direct to the results page.

    How can I make the page load the animated gif first, and then once the
    SP has run and is successful redirect?

    <img src="progress.gif" width="150" height="150" />
    <p>Please wait, upload in progress...</p>
    <%

    set cmUpload = Server.CreateObject("ADODB.Command")
    cmUpload.ActiveConnection = MM_aclv4_STRING
    cmUpload.CommandText = "dbo.updateWebshop"
    cmUpload.Parameters.Append cmUpload.CreateParameter("@RETURN_VALUE", 3, 4,2)
    cmUpload.CommandType = 4
    cmUpload.CommandTimeout = 0
    cmUpload.Prepared = true
    cmUpload.Execute()

    %>
    <% If cmUpload.Parameters("@RETURN_VALUE") = 0 Then
    Response.Redirect("results.asp")
    Else%>
    <p>Error Code: <%= cmUpload.Parameters("@RETURN_VALUE") %></p><% End if %>
     
    Dooza, Jul 15, 2008
    #1
    1. Advertising

  2. Dooza wrote on Tue, 15 Jul 2008 14:52:42 +0100:

    > I have a stored procedure that needs to be executed via an ASP page.


    > The SP does a number of tasks, mainly comparing a local table against a
    > linked server table, and updating/inserting/deleting where necessary.
    > It does this on 4 tables, one of them being fairly large, which will
    > keep on growing.


    > I have constructed the ASP page, made an animated GIF for the fake
    > progress bar, and then inserted the command to run the SP.


    > I then check the return value and if its 0 the page is redirected to a
    > results page which shows a table.


    > When I run this page I don't get to see the animated gif, the page pauses
    > until the SP is complete and redirects direct to the results
    > page.


    > How can I make the page load the animated gif first, and then once the SP
    > has run and is successful redirect?


    > <img src="progress.gif" width="150" height="150" />
    > <p>Please wait, upload in progress...</p>
    > <%


    > set cmUpload = Server.CreateObject("ADODB.Command")
    > cmUpload.ActiveConnection = MM_aclv4_STRING cmUpload.CommandText =
    > "dbo.updateWebshop"
    > cmUpload.Parameters.Append cmUpload.CreateParameter("@RETURN_VALUE", 3,
    > 4,2)
    > cmUpload.CommandType = 4 cmUpload.CommandTimeout = 0 cmUpload.Prepared
    > = true cmUpload.Execute()


    > %>
    > <% If cmUpload.Parameters("@RETURN_VALUE") = 0 Then
    > Response.Redirect("results.asp")
    > Else%>
    > <p>Error Code: <%= cmUpload.Parameters("@RETURN_VALUE") %></p><% End if
    > %>




    Have you got Buffering turned on? If so, put a Response.Flush after the img
    tag, but before the command Execute call. So long as you're not inside a
    table then the browser should render what has been sent up to that point.

    --
    Dan
     
    Daniel Crichton, Jul 15, 2008
    #2
    1. Advertising

  3. Dooza

    Dooza Guest

    Daniel Crichton wrote:
    > Have you got Buffering turned on? If so, put a Response.Flush after the img
    > tag, but before the command Execute call. So long as you're not inside a
    > table then the browser should render what has been sent up to that point.


    Hi Daniel.
    Buffering is on by default in IIS6, so I tried what you said, and it
    almost worked... the Response.Redirect at the end of the update has
    caused this error:

    Response object error 'ASP 0156 : 80004005'

    Header Error

    /webshop/upload.asp, line 26

    The HTTP headers are already written to the client browser. Any HTTP
    header modifications must be made before writing page content.

    Any idea how I can get pass this hurdle?

    Cheers,

    Steve
     
    Dooza, Jul 15, 2008
    #3
  4. Dooza

    Dooza Guest

    Dooza wrote:
    > Response object error 'ASP 0156 : 80004005'
    >
    > Header Error
    >
    > /webshop/upload.asp, line 26
    >
    > The HTTP headers are already written to the client browser. Any HTTP
    > header modifications must be made before writing page content.
    >
    > Any idea how I can get pass this hurdle?


    I ended up using some javascript instead:

    <img src="progress.gif" width="150" height="150" />
    <p>Please wait, update in progress...</p>
    <% Response.Flush() %>
    <%

    set cmUpload = Server.CreateObject("ADODB.Command")
    cmUpload.ActiveConnection = MM_aclv4_STRING
    cmUpload.CommandText = "dbo.updateWebshop"
    cmUpload.Parameters.Append cmUpload.CreateParameter("@RETURN_VALUE", 3, 4,2)
    cmUpload.CommandType = 4
    cmUpload.CommandTimeout = 0
    cmUpload.Prepared = true
    cmUpload.Execute()

    %>
    <% If cmUpload.Parameters("@RETURN_VALUE") = 0 Then
    Response.Write("<script language=javascript>window.location =
    ""results.asp"";</script>")
    %>
    <% Else %>
    <p>Error Code: <%= cmUpload.Parameters("@RETURN_VALUE") %></p>
    <% End if %>
     
    Dooza, Jul 15, 2008
    #4
  5. Dooza wrote on Tue, 15 Jul 2008 16:52:44 +0100:

    > Dooza wrote:
    >> Response object error 'ASP 0156 : 80004005'


    >> Header Error


    >> /webshop/upload.asp, line 26


    >> The HTTP headers are already written to the client browser. Any HTTP
    >> header modifications must be made before writing page content.


    >> Any idea how I can get pass this hurdle?


    > I ended up using some javascript instead:


    > <img src="progress.gif" width="150" height="150" /> <p>Please wait,
    > update in progress...</p>


    Ah, I missed the Response.Redirect further down in your code. Using client
    scripting is pretty much the only workaround for this.

    --
    Dan
     
    Daniel Crichton, Jul 16, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    0
    Views:
    3,551
  2. John Hann
    Replies:
    0
    Views:
    6,085
    John Hann
    Aug 21, 2004
  3. Charlie Zhang
    Replies:
    3
    Views:
    1,260
    Paul Lutus
    Aug 16, 2004
  4. Mike P
    Replies:
    0
    Views:
    3,311
    Mike P
    Jun 19, 2006
  5. Rob

    progress bar or guage bar

    Rob, Jul 11, 2003, in forum: ASP General
    Replies:
    6
    Views:
    202
    Chris Barber
    Jul 12, 2003
Loading...

Share This Page