简体   繁体   English

如何在数据库上运行独立的服务器端脚本

[英]How to run an independent server-side script on database

I am developing a web application that retrieves records from a database and sorts them by a number field. 我正在开发一个Web应用程序,它从数据库中检索记录并按数字字段对它们进行排序。

I would like to run a script every 24 hours to randomly update the number field for all records so that each day the list gets sorted randomly. 我想每24小时运行一个脚本来随机更新所有记录的数字字段,以便每天对列表进行随机排序。

I'm using Visual Studio 2012 Express and the Database is SQL Server. 我正在使用Visual Studio 2012 Express,而数据库是SQL Server。

Seems like it should be simple enough but my mind is boggled on how to accomplish this. 看起来它应该很简单,但我的想法是如何实现这一点令人难以置信。

My background tells me I could just create a new table with a field to log the current time. 我的背景告诉我,我可以创建一个带有字段的新表来记录当前时间。 Then every-time A user opens the webpage I could check the field and compare it with the current time to see if more then 24 hours have passed.. If so then I could recalculate the random number field. 然后每次用户打开网页我可以检查字段并将其与当前时间进行比较,以查看是否超过24小时...如果是,那么我可以重新计算随机数字段。 And update the time in my new table. 并在我的新表中更新时间。

I know this is really inefficient I don't need to keep checking the database for every user that uses the webpage if I can get the server to run the script once every 24 hours. 我知道这是非常低效的我不需要为每个使用该网页的用户检查数据库,如果我可以让服务器每24小时运行一次脚本。 I just don't have any background on the tools and or methods I need to use to accomplish this. 我对完成此任务所需的工具和方法没有任何背景知识。

  1. Just write a console application and run it as a scheduled task every 24 hours. 只需编写一个控制台应用程序,并每24小时将其作为计划任务运行。
  2. Or write a Windows Service that has a timer that goes off every 24 hours. 或者编写一个Windows服务,其中包含一个每24小时启动一次的计时器。

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

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