views:

313

answers:

6

The solution we developed uses a database (sqlserver 2005) for persistence purposes, and thus, all updated data is saved to the database, instead of sent to the program.

I have a front-end (desktop) that currently keeps polling the database for updates that may happen anytime on some critical data, and I am not really a fan of database polling and wasted CPU cycles with work that is being redone uselessly.

Our manager doesn't seem to mind us polling the database. The amount of data is small (less than 100 records) and the interval is high (1 min), but I am a coder. I do. Is there a better way to accomplish a task of keeping the data on memory as synced as possible with the data on the database? The system is developed using C# 3.5.

+1  A: 

This may probably be overkill for your situation, but it may be interesting to take a look at the Microsoft Sync Framework

Galwegian
+2  A: 

First thought off the top of my head is a trigger combined with a message queue.

Tanktalus
A: 

In ASP.NET, http://msdn.microsoft.com/en-us/library/ms178604(VS.80).aspx.

kenny
+1  A: 

SQL Notification Services will allow you to have the database callback to an app based off a number of protocols. One method of implementation is to have the notification service create (or modify) a file on an accessible network share and have your desktop app react by using a FileSystemWatcher.

More information on Notification Services can be found at: http://technet.microsoft.com/en-us/library/aa226909(SQL.80).aspx

Please note that this may be a sledgehammer approach to a nut type problem though.

Wolfwyrd
Define nut type problem? What would be a fitter approach, then?
Leahn Novash
+2  A: 

Since you're on SQL2005, you can use a SqlDependency to be notified of changes. Note that you can use it pretty effortlessly with System.Web.Caching.Cache, which, despite it's namespace runs just fine in a WinForms app.

Mark Brackett
A: 

This may also be overkill but maybe you could implement some sort of caching mechanism. That is, when the data is written to the database, you could cache it at the same time and when you're trying to fetch data back from the DB, check the cache first.

Onorio Catenacci