Using ASP.NET to start a long Job In Server.

K

Kiran Math

I am new to .NET.
I want to create a web application in asp.net. This web page when submitted
to the server, would start a web service which invokes a stored procedure(in
sql server) which would run for 6 hrs or so. and do some other logical
operations.
At the end when the job is done it would send an email back to the user.




Question:

1> Can I use web services to invoke the stored procedure?
2> Will the web services stop if the user ( browser client) closes the
browser?
3> Is this the good method to go about?

Thanks
KM
 
K

Ken Dopierala Jr.

Hi KM,

Great question! This is one of those very fun problems to solve, you know
they are fun when you can create dozens of different solutions. I will give
you two solutions (that are pretty much the same but a little different) and
I'm sure you will get many more. Here are my solutions:

1) Create a Windows Service.
2) Create an App the runs when you start up the server.

This is what either one of them would do:

1) Constantly scan a folder (file watcher).
2) Pickup new files and run the queries.
3) Email back the results.

I would then have my web app save the query to a text file in the folder
that is being watched. As soon as I save it, my service or program would
pick it up, run the query, and then email the results. I would not have
ASP.Net or a Web Service do this. Those technologies are built to be a bit
more interactive, a 6 hour operation could bore the heck out of them and to
put it bluntly cause havok.

If you are hosting this application and not using your own server then post
back. It complicates things but will make the solution a lot more fun in
the end. Good luck! Ken.

P.S. Just to keep users informed I would add this. Have the service or
program *prove* it is running by picking up the text file and moving it to
another folder. This should happen instantly, I mean fast enough that your
web app can see this happens before it responds to the user. If this
happens, I would respond to the user that their query is being processed.
If it doesn't happen I would respond to the user that their query was
received but the processor is down. Then I would have my service or
program, upon startup, email all users that their waiting query has finally
been picked up and is being processed. This way they can feel confident in
know when things are actually happening. Thanks again for this great
question!
 
S

Sami Vaaraniemi

Here are a couple of additional ideas:

3) Create a Web Service to post the request to an MSMQ. The web method
simply places the request on an MSMQ queue and returns immediately. Another
program (e.g., a Windows service) waits on the queue, processes the request
and finally sends the email.
4) Create a Web Service to post the request to a COM+ Queued Component. Upon
receiving the request, the Queued Component processes it and finally sends
the email.

These ideas (and the ideas below) all have in common that they decouple the
lengthy processing from ASP.NET, which is a good thing as ASP.NET is not
designed for doing tasks that take a long time to complete.

Regards,
Sami
 
K

Kiran Math

Ken & Sami,

Thanks you very much for the help.All the tips were useful for me.

Regards
KM
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top