I need to synchronize the data that "one client" updated and need to be refreshed on "other client" (on another room) of the same application.
1 - Which is the best approach to doing this?
I was thinking on SqlDependency but the application can also run on other database engines (I dismiss it)
I also think of a timer polling for updates, but I really donĀ“t want to check for a change periodically.
Does anybody has this problem? How did you solve it?.
2 - Additionally. When the data must be updated in the UI without obstruct the work ofo the people in the other pc?
Scenario:
3 PC working with the same data. Creating / updating records that need to be synchronized (to get the last changes that every PC made).
I hope I was clear about my situation.
Thank in advance.
If you know that you are only gonna have 2 instances of the application, then you could do it with WCF. Each of the clients acts as a server for the other one when they want to send an update.
How you want to handle updates to data being edited by both clients... that can be tricky. It depends on your type of data, if the GUI is developed to handle updates and such things.
Related
How do I get a notification whenever there is a record in a particular table in the database?
If I use a Trigger in MySQL will not work when I change database.
If I make an Ajax request every certain interval, I will make unnecessary requests and I've been punished for it in Hostmonster (escape them).
Another idea?
This guy went through the problem as me:
http://www.schiffner.com/11-excruciating-months-with-hostmonster-have-come-to-an-end/
Thank you.
Sending Ajax requests at regular intervals (long polling) may not be the best solution but I have seen this implementation in many applications and probably it is easy to implement.
One of the solutions that has not been mentioned here is a PHP script running in a scheduler. This question will help you and make things clearer. Schedule alarm notification system php
Do let me know if you need more info.
I am having a problem and I need your help.
I am working with Play Framework v1.2.4 in java, and my server is uploaded in the Heroku servers.
All works fine, I can access to my databases and all is ok, but I am experiment troubles when I do a couple of saves to the database.
I have a method who store data many times in the database and return a notification to a mobile phone. My problem is that the notification arrives before the database finish to save the data, because when it arrives I request for the update data to the server, and it returns the data without the last update. After a few seconds I have trying to update again, and the data shows correctly, therefore I think there is a time-access problem.
The idea would be that when the databases end to save the data, the server send the notification.
I dont know if this is caused because I am using the free version of the Heroku Servers, but I want to be sure before purchasing it.
In general all requests to cloud databases are always slower than the same working on your local machine. Even simply query that on your computer needs just 0.0001 sec can be as slow as 0.5 sec in the cloud. Reason is simple clouds providers uses shared databases + (geo) replications, which just... cannot be compared to the database accessed only by one program on the same machine.
Also keep in mind that free Heroku DB plans doesn't offer ANY database cache, which means that every query is fetched from the cloud directly.
As we don't know your application it's hard to say what is the bottleneck anyway almost for sure you have at least 3 ways to solve your problem. They are not an alternatives, probably you will need to use (or at least check) all of them.
You need to risk some basic plan and see how things changed with paid version, maybe it will be good enough for you, maybe not.
Redesign your application to make less queries. For an example instead sending 10 queries to select 10 different rows, you will need to send one query, which selects all 10 records at once.
Use Play's cache API to avoid repeating selecting the same set of data again and again. For an example, if you have some categories, which changes rarely, but you need category tree for each article, you don't need to fetch categories from DB every time, instead you can store a List of categories in cache, so you will need to use only one request to fetch article's content (which can be cached for some short time as well...)
Say I have a GridView, the GridView will display the data from database through WCF.
The only way I can think of is using
A timer to keep on query from WCF (simplest).
The best way to do is get notification when data changes in
database, so that would be using query notifications. But now, the
WCF is in the middle betweens the Silverlight Client and Database,
so the query notification will only goes the WCF. Then I will need
to make make the WCF to use duplex communication. (Sounds like overkill...)
Refresh...button.... (this is a joke)
Is there any better way doing it?
I used to work for a company that makes medical software, and we had an application that had to monitor doctors and orders, and be constantly updated. We used a timer, just as you described above. There were some extra components to it - for example, we could change the sampling rate in software, so that during busy times, we could ping the DB more often, during slower times, less often. Caching was implemented as well. There was also a system in place to pull a smaller amount of data first, then pull more only if needed. For example, if a doctor hadn't made his rounds since the last update, then there was no need to check to see if patient data was updated. Stuff like that.
Ok here's (a simplification of) the situation, the server side has a list of connectionstrings for different DBs on different machines (values in relevant tables keep changing by other SW).
Uppon request from the client side, the server side checks the DBs one by one and has a logic that outputs a status string.
The client side should display a datagrid with the machine name and status string for all machines. The idea is that the monitor continually refresh to show any changes in status for any of the machines.
I've implemented a first draft with RIA services which works fine, I've used a DispatcherTimer to keep refreshing the ui.
My question is ,in this scenario, is it possible to get automatic update of the UI whenever any of the underlying DB's change using RIA bindings instead of actively initiating the queries from the client with DispatcherTimer ??
Any clues will be really appreciated !
Thanks
Micha
RIA is just a layer on top of WCF service calls. You still need to poll for data changes.
You can reduce the amount of data moved across by having a "lastchanged" value cached on the server side. You poll the lastChanged value first on a regular basis and then only decide to pull the data if that value has changed.
That does of course mean some extra work server-side to update that value when changes occur, but if it all changes come in via RIA services it is pretty easy to hook in.
What is the best way to program an immediate reaction to an update to data in a database?
The simplest method I could think of offhand is a thread that checks the database for a particular change to some data and continually waits to check it again for some predefined length of time. This solution seems to be wasteful and suboptimal to me, so I was wondering if there is a better way.
I figure there must be some way, after all, a web application like gmail seems to be able to update my inbox almost immediately after a new email was sent to me. Surely my client isn't continually checking for updates all the time. I think the way they do this is with AJAX, but how AJAX can behave like a remote function call I don't know. I'd be curious to know how gmail does this, but what I'd most like to know is how to do this in the general case with a database.
Edit:
Please note I want to immediately react to the update in the client code, not in the database itself, so as far as I know triggers can't do this. Basically I want the USER to get a notification or have his screen updated once the change in the database has been made.
You basically have two issues here:
You want a browser to be able to receive asynchronous events from the web application server without polling in a tight loop.
You want the web application to be able to receive asynchronous events from the database without polling in a tight loop.
For Problem #1
See these wikipedia links for the type of techniques I think you are looking for:
Comet
Reverse AJAX
HTTP Server Push
EDIT: 19 Mar 2009 - Just came across ReverseHTTP which might be of interest for Problem #1.
For Problem #2
The solution is going to be specific to which database you are using and probably the database driver your server uses too. For instance, with PostgreSQL you would use LISTEN and NOTIFY. (And at the risk of being down-voted, you'd probably use database triggers to call the NOTIFY command upon changes to the table's data.)
Another possible way to do this is if the database has an interface to create stored procedures or triggers that link to a dynamic library (i.e., a DLL or .so file). Then you could write the server signalling code in C or whatever.
On the same theme, some databases allow you to write stored procedures in languages such as Java, Ruby, Python and others. You might be able to use one of these (instead of something that compiles to a machine code DLL like C does) for the signalling mechanism.
Hope that gives you enough ideas to get started.
I figure there must be some way, after
all, web application like gmail seem
to update my inbox almost immediately
after a new email was sent to me.
Surely my client isn't continually
checking for updates all the time. I
think the way they do this is with
AJAX, but how AJAX can behave like a
remote function call I don't know. I'd
be curious to know how gmail does
this, but what I'd most like to know
is how to do this in the general case
with a database.
Take a peek with wireshark sometime... there's some google traffic going on there quite regularly, it appears.
Depending on your DB, triggers might help. An app I wrote relies on triggers but I use a polling mechanism to actually 'know' that something has changed. Unless you can communicate the change out of the DB, some polling mechanism is necessary, I would say.
Just my two cents.
Well, the best way is a database trigger. Depends on the ability of your DBMS, which you haven't specified, to support them.
Re your edit: The way applications like Gmail do it is, in fact, with AJAX polling. Install the Tamper Data Firefox extension to see it in action. The trick there is to keep your polling query blindingly fast in the "no news" case.
Unfortunately there's no way to push data to a web browser - you can only ever send data as a response to a request - that's just the way HTTP works.
AJAX is what you want to use though: calling a web service once a second isn't excessive, provided you design the web service to ensure it receives a small amount of data, sends a small amount back, and can run very quickly to generate that response.