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.
-
I think this is the best solution. Coding it in the database itself will ensure that it gets done. I feel iffy when coding a website to do X every interval. It just feels flaky. – Only Bolivian Here Sep 19 '11 at 01:16
You can use Timer. If you use SQL Server you can also schedule a job on the DB directly.

- 91,536
- 11
- 82
- 95
-
2If he did write code involving a Timer, what application would actually host this? – Andrew Shepherd Sep 18 '11 at 23:58
-
What is wrong with a Timer? To clear the situation a little bit: I've got two tables in sql, A and B. Table A is news database yet to be added, and table B is news database showed on website. I want copy one news from A to B per hour. – Peter Sep 19 '11 at 00:23
-
2ASP.NET websites can serve pages on request, but this problem actually requires a background service. How would you go about setting a continuously running background service hosted by the ASP.NET framework? – Andrew Shepherd Sep 19 '11 at 00:34
-
I'm not sure what do you mean. I should mention, that I dont have a dedicated server, I only rent some asp.net hosting space. I found this -> http://www.codeproject.com/KB/aspnet/ASPNETService.aspx ... Do you think that would be helpful? – Peter Sep 19 '11 at 00:44
-
you can spawn a new thread that would do this in the global.asax we had a service that did a similar kind of sync in my last project – Daniel Powell Sep 19 '11 at 01:08
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/
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.

- 2,330
- 3
- 24
- 37
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

- 8,143
- 11
- 61
- 108