Schedule a job on a hosted web server

Can someone give me a better way to implement daily work with .NET technology. I have an asp.net application with a sqlserver database hosted on shared hosting, GODaddy in my instance. My application is used to add / modify data in a database, which is currently running fairly honestly. I have a new requirement to send daily email notifications based on some data criteria that were stored in the database.

I originally thought of writing a Windows service, but godaddy does not allow access to a database other than hosted applications. Does anyone have any ideas sending messages daily at 1:00?

Thanks in advance

+4
c # website
source share
6 answers

See Simple Background Tasks in ASP.NET by Jeff Atwood.

Copy / paste link:

private static CacheItemRemovedCallback OnCacheRemove = null; protected void Application_Start(object sender, EventArgs e) { AddTask("DoStuff", 60); } private void AddTask(string name, int seconds) { OnCacheRemove = new CacheItemRemovedCallback(CacheItemRemoved); HttpRuntime.Cache.Insert(name, seconds, null, DateTime.Now.AddSeconds(seconds), Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, OnCacheRemove); } public void CacheItemRemoved(string k, object v, CacheItemRemovedReason r) { // do stuff here if it matches our taskname, like WebRequest // re-add our task so it recurs AddTask(k, Convert.ToInt32(v)); } 
+5
source share

I have not used GoDaddy for anything other than domain registration, so I have no experience with what you can or cannot do on my hosting platform. I also don't know what their support or knowledge base is, but I would say that your best option is to ask GoDaddy what they recommend. Otherwise, you can continue to implement something technically feasible, but blocked by the hosting company.

If it’s not that the application is in prime time, one is quick and dirty, you need to make some external bot call a (secure) web page on the server that fires during the notification process. Not a real solution, but if this site is your hobby, it can get you until you find what the host allows.

It may also be the best time to find a new host if this does not meet your requirements. Many good ASP.NET hosts are available these days.

0
source share

You can use the window scheduler from the web server to schedule a call to a stored procedure that can send mail based on certain criteria.

 osql.exe -S servername -d database -U username -P password -Q "EXEC spAlertOnCriteria" 

Literature:

0
source share

Many hosting providers can request a URL for you every X minutes. I don’t know if GoDaddy does, but if so, you can create an ASMX page that launches the task and ask them to complete it automatically.

If they do not, one solution might be to run the job in the background thread for every page request. If you do, make sure you enter code that limits it to work every X minutes or more (possibly using a static variable or database table) - read this story

0
source share

If you can expose the service on the website that hosts the application and the authentication service with the database, of course, then you can remotely delete this service from any credential field, pull out the data and send mail in such a way

It can be an automatic process written as a Windows service, an application launched under Scheduler, or some button that you click at 1:00 AM. Your choice.

Just because an application is the only one that can access the database does not mean that you cannot expose data in other ways.

0
source share

Use System.Timers, System.Threading to create an instance that starts at a given time. Ask this thread to complete any task you want ... Make sure the code is thread safe!

-one
source share

All Articles