0

I have a LAN composed of 3 PC. Installed in PC1 is the MS SQL database. This computer will act as the server.

The PC2 and PC3 will each have a desktop application that will display the data from PC1.

My problem here is how to make each PC (PC2 and PC3) have the same copy of data. Suppose in PC2 employee 0001 first name is updated from John to Peter and commit save. Without refreshing the application in PC3, employee 0001 will still have John for the first name.

What would be the best approach for this? My level in programming is not that good, but I'm open to all suggestions/concepts/example/etc..

Thanks.

yonan2236
  • 13,371
  • 33
  • 95
  • 141

3 Answers3

2

If you want immediate update on all clients right after data changes then you need some sort of notification system either in a polled or pushed manner.

You can implement push mechanism using for example WCF with callback contract. Your client PCs would need to implement relevant callback interface and be constantly connected to server PC's WCF service. Callback call could actually carry the new data. Each client needs to filter out notifications which resulted from that client's own changes. Push mechanism is quick and efficient way.

Check this stackoverflow answer for example of WCF callback.

Pull mechanism would require a background thread on all client applications checking the server for changes. You can use a separate database table with a version counter that would get incremented each time anything changes on the server. Client applications would poll that counter, compare with latest version they have and update the data when new version is discovered. It is much less effective mechanism though as you need to do the polling frequently and get all the data each time there is a new version. You can make versioning more sophisticated and detect what exactly changed but that can get complicated quickly with multiple clients. Overall it does not scale very well. It is generally simpler than push though and for simple applications with not too much data it would be enough.

Community
  • 1
  • 1
Maciej
  • 7,871
  • 1
  • 31
  • 36
0

You need to tell the other machines when to update. This could be accomplished by simple messages sent over the network using UDP broadcast. Then the other PC could execute its refresh method.

Simon
  • 9,197
  • 13
  • 72
  • 115
-2

well utivich...this is the same thing as a web application really. it's a common problem. usually the other clients will have stale data until the record is reloaded, or when they save maybe the server will throw an exception on stale data based on sql timestamp. however, with a desktop application you can setup a system with event notification just like a chat application where the server pushes events to subscribers and the clients will be able to update the record or whatever you need to do.

Timmerz
  • 6,090
  • 5
  • 36
  • 49