I want to copy one row from table A to table B per hour on my asp.net website. How can I do that? Do I need win32 application? I would like to avoid that.
5 Answers
This sounds like you want to create a stored procedure and use the Sql Server Jobs scheduler to run it every hour. See here for details of setting that up
Or if you are using Sql Express see this question "How to run a stored procedure every day in SQL Server Express Edition?"
Ideally you wouldn't do this using IIS etc, unless there is some reason you don't have access to the database.
1 Comment
You can use Timer. If you use SQL Server you can also schedule a job on the DB directly.
5 Comments
I would agree with brodie. Alternativly create a SSIS package and run either as a SQL Job or a scheduled task from command line(using DTEXEC).
http://msdn.microsoft.com/en-us/library/ms365302.aspx - Shows you how to create a basic solution.
http://decipherinfosys.wordpress.com/2008/09/17/scheduling-ssis-packages-with-sql-server-agent/ - Shows you how to schedule your task.
For your exercise either would do the trick. I would suggest using either that you feel more familiar with. But certainly wouldnt suggest creating a timer driven service.
Comments
You could create a webpage that accomplishes this and use a free service like pingdom.com to call that page every hour.
EDIT: Mine is the easy route, probably not the best solution but quick and simple
You can check this out also: https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/
Comments
see this example for creating a new thread in global asax, http://www.mikesdotnetting.com/Article/129/Simple-task-Scheduling-using-Global.asax
Be aware though if the website goes down the process will not continue to run, if this is a problem a sql batch job or windows service would be better suited, and if the task is resource intensive it would be better to do this on another machine anyway as the global asax method will take away processing resources from your website