For a application with a database in C#, I need to call a function every month just once(on a defined day). It is necessary to check on every start of the application, if the defined day, which is registered in the database, has already been this month and if that, not to call the method again.
What would be the best way to solve? Save month and year in the database too and check if actual date > than the values in the database?
Is there a more easy way?
EDIT 1:
If I try to do that with the Windows Task scheduler, how can I contact that with C#?
My method is a Sql-Insert-Statement, that has to be done every month once on the same day.
A scheduled task, windows service or sql server agent would be better (if you have a server available).
Failing that – and provided that the function doesn’t have to run on a specific day, then your solution above seems fine.
If the function must run on the 1st can you rely on your app being ‘on’ at that time?
edit: so….you have some kind of c# application with an mdf in folder somewhere. You have an insert that must run on the 1st of the month.
I would create a scheduled task on the machine that has the app. The task would call another (tiny) C# program (.exe) command that has a connection string to your db*. This app gets called once a month and does the insert.
*
Driver={SQL Native Client};Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname;Trusted_Connection=Yes