0

I got an online website written in ASP.MVC. Now, i need to periodically check one table, and if it changes, i need to take further actions related with modifying data in other tables. I could of course write a stand-alone application that would do that for me, but what other options do i have? I am asking, because maybe there is something better which i don't know about.

ojek
  • 9,680
  • 21
  • 71
  • 110
  • 1
    Closely related question: http://stackoverflow.com/q/4329859 – Robert Harvey Nov 27 '12 at 20:49
  • That's the only way. Websites only respond to requests from the web. You can't guarantee that any page will be running at all at any given time. – Brian White Nov 27 '12 at 20:51
  • 2
    Create an update trigger: http://msdn.microsoft.com/en-us/library/aa258254(v=sql.80).aspx – Alex Nov 27 '12 at 20:51
  • Trigger sounds like a solution, but i don't like dealing with db engine too much. :/ Robert's answer on the other hand sounds just about what i need, but i am not sure how `ThreadPool.RegisterWaitForSingleObject` method will affect performance, since i need to get data from one table and put it in the other. Do you maybe have any experience dealing with that method? How it will affect performance of my website? – ojek Nov 27 '12 at 20:57
  • @ojek: You're probably asking that question too soon. The amount of effort to implement it seems minimal, and then you can decide if it's too slow for your needs. – Robert Harvey Nov 27 '12 at 21:05
  • Do you only have 1 web server? All of the asp.net solutions seem to only work in a 1 web server environment. You would hate to find out you engineered yourself into a dependency on having a trivial site down the road if this is a commercial site. Adding a separate app that can be scheduled (in a variety of ways) will work the same with 1 web server as with 50 web servers. – Brian White Nov 28 '12 at 16:01
  • Oh - this is purely database? Yes, you want a trigger. That solves the singleton actor/multiple webservers issue as well. We use triggers a lot. – Brian White Nov 28 '12 at 16:14

2 Answers2

2

Assuming that you're using SQL Server, one option would be to add an item to the ASP.NET Cache, and then register a SqlCacheDependency on that item for the table or row that is to be monitored. There is a bit of configuration required to get this up and running, some instructions are here (with the code samples being in VB). When you add the item to the cache that has a SqlCacheDependency, you can specify a callback method that is fired when the data changes, which is how you would update related tables. If you are running SQL Server, want a pre-defined solution provided by Microsoft, and don't mind the setup process and additional database tables and configuration that this includes, this would be a great option.

David Marchelya
  • 3,352
  • 4
  • 21
  • 24
  • How does this setup work with multiple webservers? For a typical cache this would be fine. All you need to do is invalidate the cache on multiple webservers. But the OP wants to have something fire that goes and updates data. That requires a singleton. – Brian White Nov 28 '12 at 16:12
  • That would certainly be a drawback to this implementation that would have to be taken into consideration, but this is not requirement spelled out in the original post. This is something that could be worked around using this approach in a multi server configuration, but at that point, then yes, you may want to consider other options. – David Marchelya Nov 28 '12 at 20:24
0

I got an answer that is satysfying my requirements. There is something called Quartz.net that works just as i wanted it to. :)

ojek
  • 9,680
  • 21
  • 71
  • 110