views:

411

answers:

8

We require that in a ASP.Net application, a .Net process should be invoked every day at a specified time automatically. This process needs to interact with the database (SQL Server 2005) and generate billing on a daily basis. We are using a shared hosting hence we are not able to create a windows service or create SQL Server jobs. How can this be achieved without user intervention?

+2  A: 

You could always schedule a task to run a webservice..

http://weblogs.asp.net/jgalloway/archive/2005/10/24/428303.aspx

The scheduler would run a VBS file with the following..

Set oServerXML = CreateObject("Msxml2.ServerXMLHTTP")
oServerXML.Open "GET","http://my.hostedservice.com/myService.asmx/myService?aParam=Value
oServerXML.setRequestHeader "Content-Type","application/x-www-form-urlencoded" 
oServerXML.Send
Set oServerXML = nothing
madcolor
he said he is on shared hosting so no way to access windows schedule
Amr ElGarhy
The scheduled task would run on another server.
madcolor
If on another server, so will work
Amr ElGarhy
A: 

You can use a Scheduled Task, but this might not work in a shared hosting environment either.

You could setup a webservice or page on your website to kickoff the process, then have a scheduled task on a desktop machine hit that page/service once daily to start the process. Hacky, but it might work.

Jason
+1  A: 

Can't be done, unfortunately.

IIS only responds to requests, and SQL Server only wakes up for jobs.

The closest you'll be able to do is to put your routine in an ASPX page, not linked from the site and not with an obvious name, and trigger it by a request from some other machine out on the Internet.

The other machine could be a Windows, Linux, Mac, whatever you have available, and all of those platforms have ways of scheduling events (service, cron, etc.) that can make the request to trigger the update on the server.

richardtallent
+3  A: 

Yes, use Windows Scheduler. Depending on how it's configured you might need to be logged in for the scheduler to run.

rein
on shared hosting no way to access windows schedule
Amr ElGarhy
But there is the option of placing a web service on the hosting environment and then having an external, always-on box invoke it.
Nathan Taylor
A: 

Being .NET ignorant, I would imagine there's some kind of .NET based scheduler framework available for this (much like Quartz for Java).

Or you could simply fire off a long running thread that spends the bulk of its time sleeping, wake up every minute, check the time, check it's list of "things to do", fire off the ones that need to be done. Level of sophistication being as far as you want to take it, but the primary goal of keeping the primary scheduling thread "alive", "at all costs".

Will Hartung
A: 

What i can think about now are:

  • Create a dll which contain the schedule logic you want, and make sure that this dll schedule function will not stop and will loop for ever, then you will need a page on that server this page will fire this dll functions. "you will need to call this page at least once to start the scheduler".

  • Create an application "holds schedule logic" on another machine, may be your Home PC, and make your pc application call the functions on the server through webservices or pages

Amr ElGarhy
+1  A: 

There are ways to run "services" in .Net by using cache expiration to trigger the task.

More at CodeProject

Joel Potter
+10  A: 

You could try the technique described here, used at StackOverflow itself (or at least it was used here at one point). In a nutshell:

  1. At startup, add an item to the HttpRuntime.Cache with a fixed expiration.
  2. When cache item expires, do your work, such as WebRequest or what have you.
  3. Re-add the item to the cache with a fixed expiration.

To get it to run at a specific time instead of an interval, you could lower the interval and simply modify your working method to check the time itself.


As the comments in the original article linked above note, this isn't a perfect solution, and no one should prefer it over a proper scheduling technique if one is available. See When Does Asp.Net Remove Expired Cache Items? for some additional qualifications.

Jeff Sternal
Fixed expiration times are not fixed... they only *actually* expire when you attempt to ACCESS the cached item again. That's fine for a constant-traffic site like SO, but it is not dependable for sites where you can't depend on traffic to ping the site close enough after expiration (and hit the cache item so it expires) to perform the work when you need it.
richardtallent
@richardtallent: that is not correct, though the cache expiration mechanism is more complicated than I thought and requires more consideration before using blindly! See the link I've added to my answer for more details.
Jeff Sternal
@jeff: read your link yesterday, great research!
richardtallent
@richardtallent - thanks, it was really interesting. (By the way, your photography is amazing!)
Jeff Sternal