开发者

The best way of triggering a timely event

开发者 https://www.devze.com 2023-01-25 08:02 出处:网络
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 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 w开发者_高级运维ill 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消