The best way of triggering a timely event - c#

I am building an ASP.Net website, I have a db table which I want to reset a column in it for all rows. column type: byte
I want to do this every day at midnight, in an automatically way. I know I can set a job in SQL Server Management Studio but I want to do this in a programmatic way and my website will be the trigger for it.
I'm using C#.Net 2008 and MS SQL Server 2005
i.e. (Pseudo code)
if(new_day)// can we be accurate that time here will be around 12:00:05 at maximum?
// call sql stored procedure to reset that column

You could make a simple Windows service in C# that would run in the background but considering all you want to do is make database updates, it's best to keep it in the DB....I'd suggest going with the scheduled job in SQL

Your website only executes when a page is requested making it unable to act as a service that executes a task at regular intervals. The best solution is to use SQL Server directly to schedule the task, create your own service or execute an application at regular intervals using Windows task scheduler.
However, if you for are in hosted environment you may not be able to do any of this. In that case you can use the cache to simulate a service. Omar Al Zabir has an article on CodeProject that explains how you can do that: Simulate a Windows Service using ASP.NET to run scheduled jobs.

If you really want to: create a Scheduled Task that calls your website every day at midnight. The website itself cannot trigger itself, but a task can do this.
But really: just set up a SQL job.

SQL Agent job, scheduled to run at the specified time.

Related

How to run a scheduled job on Azure?

I am planning to create a service that checks something on a website with an interval. Compares the results with the DB and sends a email out if changes has been made.
No user interface is needed.
What type of service should I use for this type of application?
There's no single correct answer to your question. If you want to keep things really lightweight, you could use an Azure Function App with a timer trigger.
If the Function App model isn't right for you, you can deploy a scheduled Web Job to an App Service deployment.
For some scenarios, the best alternative is a virtual machine with cron / Windows Task Scheduler. For others, it's to write an app that comes with its own scheduler.
You can try to look at Azure Functions. That is probably the simplest thing you can do and it can run on timer. That seems quite relevant to your use case.
Azure Functions supports an event based on a
timer using Cron job syntax. For example, execute code that runs every
15 minutes and clean up a database table based on customised business
logic.

using timer in asp.net for performing insertion to a database at a particular time

I want to add all my contents in my tables in local database to server database at the end of day automatically.Is it possible by setting timer in login page.Or else any other way.
I am using C# ASP.net 2008,SQL 2005.
Idea 1: You could create a console application that is executed with the Windows Task Scheduler at a particular time. This console will copy the data (e.g. since the last run) to the remote DB.
Idea 2: Maybe you can use SQL replication to solve it, without any custom code.
Idea 3: create a Windows-NT service that copy the local data to the remote DB.
I wouldn't use a timer within the asp.net application. This is definitely not the way to implement such things.

Looking to run automated jobs in .NET application

Within a .NET application (.NET Framework 4.5), the following is occurring:
A single record in a table in an SQL Server database is referred to as a job
When the job is run, C# code is called
Briefly to explain what it is doing, the job, when run, converts PDFs in a folder directory location, to images in SQL Server
Currently, these jobs run successfully, when the user manually runs them
Does anyone have a recommendation on how these jobs may be run as automated, and not require user intervention? I'm trying to find a process similar to the following:
A daily process will look for all jobs that have a 'next run date' of the current date (the 'next run date' will be stored in a table/column in SQL Server)
When a job is run, the C# code is to be called and run, without user intervention
If you can insert the first part of your requirement (to look for all jobs that have a 'next run date' of the current date (the 'next run date' will be stored in a table/column in SQL Server)) in the C# application that is already executed manually then you only need a Task Scheduler to Execute this C# Application on a daily basis.
you basically need to set up a CRON job. If your "job" can operate on a URL, you could use a service like "easycron.com" to set up a call to this URL at regular intervals.
Alternatively, the same thing might be possible with your hosting if they allow CRON jobs to be set up.
If this isn't a web-facing app - maybe a scheduled task calling the app (if it is a console based EXE) directly on the server. You'll obviously need access to the server at an admin level for that.

SQL Server Azure - Executing stored procedure every x minutes

Generally with SQL Server, I could setup a job and have it run every so often. Something like this. However SQL Server Azure does not seem to have this ability.
My thoughts were to instead, have a service that runs this procedure every x minutes. I'm just wondering if anyone sees any issues with that, or has any better suggestions?
The stored procedure takes some xml data stored in one table and normalizes it across other tables making it easier to query on.
You can schedule jobs using the new Scheduler:
http://weblogs.asp.net/scottgu/archive/2012/12/21/great-updates-to-windows-azure-mobile-services-web-sites-sql-data-sync-acs-media-more.aspx
More Detail:
http://www.windowsazure.com/en-us/develop/mobile/tutorials/schedule-backend-tasks/
If you are open to using a service, Cotega offers the ability to schedule execution of stored procedures from within SQL Azure. You can read more about how to schedule these jobs here.
Full disclosure, I work on this service.
You can trigger scheduled task running procedure directly from your application using, for example, Quartz.

Scheduling in Asp.net.What is best solution?

I want to Scheduling in Asp.net
I have following options to implement this
To write SQLServer JOB(I dont want to do this.Dont want to go outside of .Net environment)
Second option is I will write windows service and this window service will call asp.net
webservice then this webservice calls asp.net method
(I also dont need to do this because my hosting provider might not be allow me to install
window service)
Third option is I call my scheduling method in Application_Start event in global class
(Drawback is, webserver will kill thread any time )
To call Scheduling Code in Page_Load event of Home Page(Might be nobody visits my website for hours
,Also page execution might be slow due to scheduling code)
I also found some online services that calls your page at given interval,some are given below
http://www.cronservice.co.uk/new/
http://scheduler.codeeffects.com
Anybody give me bettor solution of this and also explain why it is bettor?
Thanks in Advance
The ASP.NET application isn't the right place to implement scheduling. I would suggest creating a service or a scheduled task that runs in short intervals.
You don't have many options in a shared hosting environment. My host (WinHost) allows remote access to their database, so I was able to create an executable that ran on a local server with Task Scheduler.
The performance isn't great since the database is accessed over the internet, but it's still better than attempting to run pseudo scheduled tasks with ASP.NET.
Some hosts also offer a service that will request a url within your site on a scheduled basis. However, this didn't work for me because the task I had to run took longer than the request timeout.
There is no one solution that fits all. SQL jobs and windows jobs (scheduled thru windows task scheduler) are very widely used. In one of my previous work places they had jobs that ran on multiple platforms (mainframe,windows,sql server). Failure in some of these jobs, would cost in thousands by the day. So they employed something called ESP. This software monitored jobs on all platforms and sent a message to the control room in case of a failure.
If you throw some more light on the requirement, we might be able to help you better.
ASP.NET is not the right place to house your Scheduled Tasks. I'm using Quartz.net when I have to create Scheduled Tasks.
Create a page that launches your task and place it at the URL http://www.mydomain.com/runtask.
Create a scheduled task on your home PC that sends a request to http://www.mydomain.com/runtask.
You'll need to keep your home PC on all the time.
Ideally I would go with number 1 as you get full control/history/error reporting etc. You can write an SSIS job in .NET and have SQL server schedule it.
However, I have had a similar problem with shared hosting that is very restrictive. What I did was create a page which runs the process on page load (using validation in the querystring for security). I then used a machine I have which is always on to schedule a Windows Task Scheduler (this is part of Windows as standard) to call a bit of VB script that opens the browser and then shuts it.

Categories

Resources