How to update the database once when the timer expires?

279 Views Asked by At

I am using an ASP.NET web form and I have two fields Start_date and End_date in it.

I want to update a particular field in SQLServer once when the time goes beyond the End_date (i.e. the deadline is expired).

e.g. if the End_date is on 06/09/2015, then the SQLServer field should be updated as Expired at 12.01 AM on 06/10/2015.

I am new to ASP.NET and please let me know if you have any ideas. Thank you

2

There are 2 best solutions below

0
On

There are way too many ways to do such thing. I.e:

  • making a SQL script that does that and adding that script as scheduled job in SqlServer
  • or, creating a WindowsService that sleeps and wakes up every hour or six and checks for expired records
  • or, adding a module like Hangfire to your ASP application and adding such scheduled task there
  • ..

Those three are probably the most often used.

Anyways, it's always about some scheduler and some job to do periodicaly. Think how to write one "run" of the job (find expired, mark/delete them), then read about what schedulers you can use, then glue it together and configure the scheduler and done.

0
On

There are several ways to do this, but if all you need to do is make database changes at a given time, then I recommend using the SQL Server Agent. You can set it up to run just once or on a recurring schedule and you can set it up to run a stored procedure or you can feed it straight SQL commands.