Technique(s) in a C# multiuser application where all clients have their data up-to-date from a central database

StackOverflow https://stackoverflow.com//questions/11657277

Question

In a multiuser environment: How do you make sure that all clients see eachothers changes? What is the best way to do this?

In the past I created a C# application and installed it on 2 pc's. It connected to a central SQL Express server (the client application worked with Entity Framework Code First as ORM). When client1 added a record to the database, this was not directly visibly to client2. Only if client2 fetched all data again (hard refresh) the change was visible.

Now I am looking for a solution on how this 'sync'(?) can or should be done. I like working Entity Framework Code First, it would be nice a solution could keep this. Also the application is still in a very early stage. I thought by having a central database and multiple clients connecting to it, but I'm not sure if this is a good solution. If your suggestions/solutions would require a central server application where the clients connect to (and where the server application does the database handling) this would be no problem.

If possible a basic sample solution or some basic code that shows how to always work with the latest data could would be very helpful!

Similar questions:

Thanks in advance

Était-ce utile?

La solution

It depends on your environment and the data you are managing and the architecture you want.

If it's OK/acceptable to let clients have copies of the data which they can work with, they need to work with the data when not connected to the central server, then you could use the the Sync Framework.

You'd have your central SQL Server as usual, and use the Sync Framework to sync with clients.

You would write a "Provider" which would decide how to resolve changes made to the same data by different clients, etc.

You would have to put SQL Express (or possibly LocalDB (new name for SQLCE)) onto the client machines.

Then do your Entity Framework Model/Code to access the local database instead of a central one.

http://blogs.msdn.com/b/sync/archive/2008/06/24/sample-sql-express-client-synchronization-using-sync-services-for-ado-net.aspx

Otherwise it's down to designing and implementing some "tiers" and following a Distributed Internet/Database Architecture/SOA.

A nice free resource:

http://msdn.microsoft.com/en-us/library/ff650706.aspx

http://mtechsoa2011.blogspot.co.uk/2011/04/soa-vs-distributed-internet_27.html

Some useful books:

http://www.amazon.co.uk/Service-Oriented-Architecture-Concepts-Technology-Computing/dp/0131858580/ref=sr_1_1?s=books&ie=UTF8&qid=1343295432&sr=1-1

Autres conseils

Other solution is create an "interface" for your database and each put data operation from some client can notify other clients. You can implement such interface by WCF with it's callbacks. I have no simple code for whole architecture solution... If you'll ask more concrete question about building n-tier application with WCF I'll try to help.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top