1

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 5

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
2

You can use Timer. If you use SQL Server you can also schedule a job on the DB directly.

5 Comments

If he did write code involving a Timer, what application would actually host this?
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.
ASP.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?
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 -> codeproject.com/KB/aspnet/ASPNETService.aspx ... Do you think that would be helpful?
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
2

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

2

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

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.