473,385 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Calling ASP function asynchronously

I have an ASP application that calls a COM function to create a custom
report as an Excel file. This works in a synchronous fashion, as long as
the report does not take too long to create. If that happens, the session
times out and we run into other kinds of problems.

I have, in other cases, executed a stored procedure asynchronously (thanks
to a tip from this group) thru ADO.

I'm wondering if ASP provides some way of executing a function (an ASP
function, not ADO) asynchronously? I could then make the call to the COM
function from within this async thread, and implement the same refresh logic
on the client that we used in the ADO solution.

tia,

Bob M..
Jul 19 '05 #1
4 5702

AFAIK there is no way to make an asynchronous call to a VBScript function,
since you can't define events in ASP, and that's something you need to be
able to know you results have return properly,

but, since you managed to work async with a stored procedure through ADO,
maybe there's a way to call the COM object from an stored proc which is
perfectly possible if you are using MS SQL server as your DB.

Btw, I'm curious how that async stored-procedure magic works in ASP though,
would you mind sharing a snippet of code? :)

"Bob Murdoch" <ra***********@erols.com> wrote in message
news:e1**************@TK2MSFTNGP10.phx.gbl...
I have an ASP application that calls a COM function to create a custom
report as an Excel file. This works in a synchronous fashion, as long as
the report does not take too long to create. If that happens, the session
times out and we run into other kinds of problems.

I have, in other cases, executed a stored procedure asynchronously (thanks
to a tip from this group) thru ADO.

I'm wondering if ASP provides some way of executing a function (an ASP
function, not ADO) asynchronously? I could then make the call to the COM
function from within this async thread, and implement the same refresh logic on the client that we used in the ADO solution.

tia,

Bob M..

Jul 19 '05 #2

"J. Baute" <WU**********@spammotel.com> wrote in message
news:40*********************@news.skynet.be...

AFAIK there is no way to make an asynchronous call to a VBScript function,
since you can't define events in ASP, and that's something you need to be
able to know you results have return properly,
That's what I figured. Couldn't hurt to ask though.
but, since you managed to work async with a stored procedure through ADO,
maybe there's a way to call the COM object from an stored proc which is
perfectly possible if you are using MS SQL server as your DB.
Yech. No MS Sql Server here. I'm using Firebird. I could probably put
together a UDF to make the call, but that doesn't seem to be a proper
seperation of the data/application layers. More likely, I'll implement the
call to our middle tier in the com object, and let the middle tier create
the report.

Btw, I'm curious how that async stored-procedure magic works in ASP though, would you mind sharing a snippet of code? :)


Sure.

We've got an include file called DbLibrary.asp, which contains all of the
logic for connecting/opening datasets/disconnecting. In this library is the
function for executing an async query:

function ExecuteSqlAsync(ASQL)
{
var vCount = 0;
vDBConnection.Execute(ASQL,vCount,0x10);
}

The 0x10 flag is equivalent to the constant adAsyncExecute.

The long running process is kicked off when a user makes a change to a
pricing model. We first generate a unique id for tracking the progress of
this event, then kick off the stored procedure via the above call. We then
redirect to a generic please wait page. This page shows a message to the
user, as well as an animated progress bar. It also contains an invisible
IFRAME, whose source is a page called WaitBackground.asp.

WaitBackground contains a refresh header set to 5 seconds. Each time the
page refreshes, it checks a table to see the status of the job (keyed by the
ID mentioned above, and updated by the stored procedure). If the job status
is complete, we use client side js to do a 'parent.document.location = ',
and show whatever page the user should be taken to.

All in all, it works very well, for both the short updates (the user sees
the progress screen for just a few seconds), and for longer updates (they
still have to wait, but are entertained by the animated progress bar moving
back and forth <g>).

Bob M..

<!--#include virtual='/Shared/Server/DbLibrary.asp' -->
<%

function SaveStopRateModel(AProcessStatusId)
{
vSql =
"execute procedure inv_save_stop_rate_revision(" +
Request('revid') + "," +
AProcessStatusId + ");"
ExecuteSqlAsync(vSql);
}

ConnectDb();
var vNewId = GetNewId2('PROCESS_STATUS_GEN');
SaveStopRateModel(vNewId);
Session("ProcessStatusUrl" + vNewId) = 'StopRateEdit.asp';
Session("ProcessStatusMsg" + vNewId) = escape(
'Your changes to the stop rate model are being saved.<BR><BR>' +
'Please wait while salescheck stop rates are updated based on your
selected "Effective Date".<BR><BR>' +
'This process could take up to two minutes. You will be returned to the
stop rate editor when complete.');
Response.redirect('PleaseWait.asp?processid=' + vNewId);
%>

Jul 19 '05 #3

Thanx, and interesting piece of code to say the least,

btw,
couldn't you use a simular technique to create that Excel report?

Why not call a .vbs script from ASP by using the WScript.Shell Run() method
with the param bWaitOnReturn parameter set to False, which should just call
the VBS script and get on with the rest of the ASP code.

That way the VBS script is generating the Excel report in a seperate process
running on your webserver, and you can present the user with another one of
those fancy progressbars they like so much <g> until the report is fully
generated.

Calling a COM object from a .VBS script is practically the same as from
ASP, so I'm thinking this should work.

"Bob Murdoch" <ra***********@erols.com> wrote in message
news:O6*************@tk2msftngp13.phx.gbl...

"J. Baute" <WU**********@spammotel.com> wrote in message
news:40*********************@news.skynet.be...

AFAIK there is no way to make an asynchronous call to a VBScript function, since you can't define events in ASP, and that's something you need to be able to know you results have return properly,
That's what I figured. Couldn't hurt to ask though.
but, since you managed to work async with a stored procedure through ADO, maybe there's a way to call the COM object from an stored proc which is
perfectly possible if you are using MS SQL server as your DB.


Yech. No MS Sql Server here. I'm using Firebird. I could probably put
together a UDF to make the call, but that doesn't seem to be a proper
seperation of the data/application layers. More likely, I'll implement

the call to our middle tier in the com object, and let the middle tier create
the report.

Btw, I'm curious how that async stored-procedure magic works in ASP though,
would you mind sharing a snippet of code? :)


Sure.

We've got an include file called DbLibrary.asp, which contains all of the
logic for connecting/opening datasets/disconnecting. In this library is

the function for executing an async query:

function ExecuteSqlAsync(ASQL)
{
var vCount = 0;
vDBConnection.Execute(ASQL,vCount,0x10);
}

The 0x10 flag is equivalent to the constant adAsyncExecute.

The long running process is kicked off when a user makes a change to a
pricing model. We first generate a unique id for tracking the progress of
this event, then kick off the stored procedure via the above call. We then redirect to a generic please wait page. This page shows a message to the
user, as well as an animated progress bar. It also contains an invisible
IFRAME, whose source is a page called WaitBackground.asp.

WaitBackground contains a refresh header set to 5 seconds. Each time the
page refreshes, it checks a table to see the status of the job (keyed by the ID mentioned above, and updated by the stored procedure). If the job status is complete, we use client side js to do a 'parent.document.location = ',
and show whatever page the user should be taken to.

All in all, it works very well, for both the short updates (the user sees
the progress screen for just a few seconds), and for longer updates (they
still have to wait, but are entertained by the animated progress bar moving back and forth <g>).

Bob M..

<!--#include virtual='/Shared/Server/DbLibrary.asp' -->
<%

function SaveStopRateModel(AProcessStatusId)
{
vSql =
"execute procedure inv_save_stop_rate_revision(" +
Request('revid') + "," +
AProcessStatusId + ");"
ExecuteSqlAsync(vSql);
}

ConnectDb();
var vNewId = GetNewId2('PROCESS_STATUS_GEN');
SaveStopRateModel(vNewId);
Session("ProcessStatusUrl" + vNewId) = 'StopRateEdit.asp';
Session("ProcessStatusMsg" + vNewId) = escape(
'Your changes to the stop rate model are being saved.<BR><BR>' +
'Please wait while salescheck stop rates are updated based on your
selected "Effective Date".<BR><BR>' +
'This process could take up to two minutes. You will be returned to the
stop rate editor when complete.');
Response.redirect('PleaseWait.asp?processid=' + vNewId);
%>

Jul 19 '05 #4
"J. Baute" <WU**********@spammotel.com> wrote in message
news:40***********************@news.skynet.be...


Why not call a .vbs script from ASP by using the WScript.Shell Run() method with the param bWaitOnReturn parameter set to False, which should just call the VBS script and get on with the rest of the ASP code.


Now that, my friend, is a good idea indeed. I just might have a go at that.

Thanks for the idea.

Bob M..
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Al Christoph | last post by:
I have a program that mixes wizard like behavior with random access to the various dialogs in the wizard. I do this by having each step map to a toolstripmenuitem. Users can randomly choose the...
15
by: Bryan | last post by:
I have a multi-threaded C# console application that uses WMI (System.Management namespace) to make RPC calls to several servers (600+ ) and returns ScheduledJobs. The section of my code that...
2
by: adrin | last post by:
hello, im calling a function from an unmanaged dll which takes a ref to structure as an argument. one of the struct's fields is an address to a callback function/event(it depends on you what to...
1
by: | last post by:
How can I handle an error while I calling web service asynchronously?
0
by: han zhiyang | last post by:
I have two new questions. 1. my exception handling codes works well when I synchronously call a web service,but How can I use it in asynchronously calling? I tried in the same way,but when error...
6
by: Lak | last post by:
Hi all I am trying to call a C# method (in a DLL) asynchronously from VB. I don't know how to do this. Any suggestion is appreciated. Thanks.
1
by: JamesK | last post by:
Hi there, Hoping someone might have an idea of whats going on here, I presume I'm in the right forum but not 100%. I have a java web service that I am using with a C# .NET client. ...
4
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread...
0
by: =?Utf-8?B?dGhlamFtaWU=?= | last post by:
In the sample VB application for Filestream.BeginWrite Method, there is no NEW implementation on the AsyncCallBack Object and sample below calls for declaring both the "State" object and the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.