-4

If you have a desktop application on different clients which use the same database how do you notify the other clients if one client has changed data. Say if you as a client number 1 is looking at a datagrid with different customers and client number 2 updates a name on one of the customers you are looking at in the datagrid. How do client number 1 become aware of the change from the database? I do not think the solution would be to pull every second to the server. So what would be the choice?

tereško
  • 58,060
  • 25
  • 98
  • 150
Layior
  • 11
  • 3
  • 1
    That's a very complex application design, way above a new user's level. If we're talking about updating through a webapi (not sure, you use asp.net yet refer to desktop apps), then you'd want to keep a connex between the server and clients open, such as signalr. Good luck with that. –  Jan 29 '15 at 14:45
  • Broadly, I'd expect an edit in a client to change data via the server, and the server to *broadcast* an update notification via some messaging mechanism (e.g. JMS, AMQP etc.). That would notify each client to perform a refresh or similar. – Brian Agnew Jan 29 '15 at 14:47
  • Your question is too broad, however if you read Martin Fowlers Enterprise Architecture book, he does discuss this very complexity with techniques to combat it and at the cost to your application they have. I'd also look into congruency. If your database is stored remotely, you could potentially use sockets to poll the connection. – Greg Jan 29 '15 at 14:49

2 Answers2

1

You can use technology such as SignalR to notify the clients that there has been a change, and give them the opportunity to force a refresh (or silently update the table if it doesn't cause any conflicts, perhaps by fading in new rows).

This avoids the need to constantly poll the server for changes. You'll still have conflicts (perhaps a client disconnects and makes a change) but you can figure out the best way to handle those for your needs.

I discuss several ways of accomplish this with web clients in How to implement real time data for a web page. The technique is similar for desktop applications, as there are SignalR clients available for .NET in addition to JavaScript.

Note that this technique isn't limited to SignalR. Other technology stacks exists such as Socket.IO, but SignalR is going to have the tightest integration with .NET since it's from Microsoft.

Community
  • 1
  • 1
mason
  • 31,774
  • 10
  • 77
  • 121
0

You can take a look at the Observer Pattern:

Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

So essentially, whenever a client presses Save (or any other action which changes the data) your server would send notifications to its client. The client will then check to see if this change will affect the user. If it does, the client could then ask the server for a fresh copy of the data (ideally before notifying the user that new data is available).

npinti
  • 51,780
  • 5
  • 72
  • 96
  • This doesn't really answer the question, apart from a bird's eye perspective. The logical next questions will be _"How to implement the observer pattern in a desktop application where there is no server, only a database"_. – CodeCaster Jan 29 '15 at 14:56
  • @CodeCaster: Assuming that access to the server was available, one could write a thin layer between the database and the client which will act as a server if you will. This would also stop clients from directly accessing the database. – npinti Jan 29 '15 at 15:09
  • For the average application that does something more than CRUD, that layer won't be thin nor trivial to implement. All I'm saying is that your answer raises more questions than it answers. – CodeCaster Jan 29 '15 at 15:11