简体   繁体   English

每小时ASP.NET更新数据库

[英]ASP.NET Update database every hour

I want to copy one row from table A to table B per hour on my asp.net website. 我想在asp.net网站上每小时从表A复制一行到表B。 How can I do that? 我怎样才能做到这一点? Do I need win32 application? 我需要win32应用程序吗? I would like to avoid that. 我想避免这种情况。

This sounds like you want to create a stored procedure and use the Sql Server Jobs scheduler to run it every hour. 听起来您想创建一个存储过程并使用Sql Server Jobs调度程序每小时运行一次。 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?" 或者,如果您使用的是Sql Express,请参见以下问题:“如何每天在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. 理想情况下,除非有某些原因您无权访问数据库,否则您将不会使用IIS等进行此操作。

You can use Timer . 您可以使用Timer If you use SQL Server you can also schedule a job on the DB directly. 如果使用SQL Server,则还可以直接在DB上计划作业。

You could create a webpage that accomplishes this and use a free service like pingdom.com to call that page every hour. 您可以创建一个完成此任务的网页,并使用免费服务(如pingdom.com)每小时调用一次该页面。

EDIT: Mine is the easy route, probably not the best solution but quick and simple 编辑:我的是一条简单的路线,可能不是最好的解决方案,但又快速又简单

You can check this out also: http://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/ 您也可以查看以下内容: http : //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). 或者创建一个SSIS包,并作为SQL作业或从命令行(使用DTEXEC)作为计划任务运行。

http://msdn.microsoft.com/en-us/library/ms365302.aspx - Shows you how to create a basic solution. http://msdn.microsoft.com/zh-cn/library/ms365302.aspx-向您展示如何创建基本解决方案。

http://decipherinfosys.wordpress.com/2008/09/17/scheduling-ssis-packages-with-sql-server-agent/ - Shows you how to schedule your task. http://decipherinfosys.wordpress.com/2008/09/17/scheduling-ssis-packages-with-sql-server-agent/-向您展示如何安排任务。

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. 但是肯定不会建议创建计时器驱动的服务。

see this example for creating a new thread in global asax, http://www.mikesdotnetting.com/Article/129/Simple-task-Scheduling-using-Global.asax 有关在全局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 请注意,如果网站关闭,该过程将不会继续运行,如果这是一个问题,则最好使用sql批处理作业或Windows服务,如果该任务占用大量资源,则最好在另一台计算机上执行此操作无论如何,因为全局asax方法将占用您网站的处理资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM