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.
Related
We have a requirement for notifying external systems of changes in data in various tables in a SQL Server database. The choice of which data to monitor is somewhat under the control of the user (gets to choose from a list of what we support). The recipients of the notifications may be on a locally connected network (i.e., in the same data center) or they may be remote.
We currently handle this by application code within our data access layer that detects changes and queues notifications on a Service Broker queue which is monitored by a Windows service that performs the actual notification. Not quite real time but close enough.
This has proven to have some maintenance problems so we are looking at using one of the change detection mechanisms that are built into SQL Server. Unfortunately none of the ones I have looked at (I think I looked at them all) seem to fit very well:
Change Data Capture and Change Tracking: Major problem is that they require polling the captured information to determine changes that are to be passed on to recipients. I suspect that will introduce too much overhead.
Notification Services: Essentially uses SQL Server as a web server, which is a horrible waste of licenses. It also requires access through at least two firewalls in the network, which is unacceptable from a security perspective.
Query Notification: Seems the most likely candidate but does not seem to lend itself particularly well to dynamically choosing the data elements to watch. The need to re-register the query after each notification is sent means that we would keep SQL Server busy with managing the registrations
Event Notification: Designed to notify on database or instance level events, not really applicable to data change detection.
About the best idea I have come up with is to use CDC and put insert triggers on the change data tables. The triggers would queue something to a Service Broker queue that would be handled by some other code to perform the notifications. This is essentially what we do now except using a SQL Server feature to do the change detection. I'm not even sure that you can add triggers to those tables but I thought I'd get feedback before spending a lot of time with a POC.
That seems like an awful roundabout way to get the job done. Is there something I have missed that will make the job easier or have I misinterpreted one of these features?
Thanks and I apologize for the length of this question.
Why don't you use update and insert triggers? A trigger can execute clr code, which is explained enter link description here
I have application that generates a lot of numbers and writes them to table in sql Database.
When the process writes the numbers to the table , I give an option to watch the numbers that have been already written to the DB. I want to do it "Live".
The thing is that I have a DLL that handles the DB management , and in my UI I use this DLL. So I cant bind the ListBox to the table of numbers because the UI doesn't "know" that table.... What could be the best solution for that?
Well there are 3 solutions that come to my mind:
poll periodically the DB from the user facing app. So there is a thread running which every x seconds picks up the values from the DB, and then transfers them to the client.
You can use the Sql Notification Services in case you are using sql server to push the changes to the client, then you don't have to poll.
the last option, I guess will be an overkill for you, but the producing "app" can notify the displaying app via e.g. a message queue, or a WCF call.
Imho No1 fits for you best, but I cannot judge more precisly because I don't know expected load, ....
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.
I have an application that consists of a database and several services. One of these services adds information to the database (triggered by a user).
Another service periodically queries the databases for changes and uses the new data as input for processing.
Until now I used a configurable timer that queries the database every 30 seconds or so. I read about Sql 2005 featuring Notification of changes. However, in Sql 2008 this feature is deprecated.
What is the best way of getting notified of changes that occurred in the database directly in code? What are the best practices?
Notification Services was deprecated, but you don't want to use that anyway.
You might consider Service Broker messages in some scenarios; the details depend on your app.
In most cases, you can probably use SqlDependency or SqlCacheDependency. The way they work is that you include a SqlDependency object with your query when you issue it. The query can be a single SELECT or a complex group of commands in a stored procedure.
Sometime later, if another web server or user or web page makes a change to the DB that might cause the results of the previous query to change, then SQL Server will send a notification to all servers that have registered SqlDependency objects. You can either register code to run when those events arrive, or the event can simply clear an entry in the Cache.
Although you need to enable Service Broker to use SqlDependency, you don't need to interact with it explicitly. However, you can also use it as an alternative mechanism; think of it more as a persistent messaging system that guarantees message order and once-only delivery.
The details of how to use these systems are a bit long for a forum post. You can either Google for them, or I also provide examples in my book (Ultra-Fast ASP.NET).
Yes, this blog post explains that Notification Services is now deprecated, and also what the replacements or alternatives are, going forward.
For your purposes - getting notified of changes that occurred in the dataase - it sounds like you want SQL Server Change Tracking. But the notification is a pull model - your app has to do the query on the change table.
I failed to figure out if SqlDependency continues to work with Notification Services deprecated.
There are a number of different ways of tracking changes in the database: either by triggers that maintain temporal structures such as backlogs, tracking logs (aka 'audit tables') or using the change-tracking facilities in SQL 2008 as references in another answer. Irrespective of whatever mechanism you use, you have the problem of notifying your homegrown service of the change. For this, you can use the Service Broker and event-based activation. From what you describe, it seems like having the application wait on an event from the queue.
http://msdn.microsoft.com/en-us/library/ms171581.aspx
If you don't wish to have the service hang around and sleep on the queue, you can investigate into firing the service into life 'on-demand' by using the external activation mechanism in service broker.
You can use the System.Data.SqlClient.SqlDependency (which works with Service Broker on) to subscribe to changes in a table.
I'm developing a client-server app using WCF and Linq2Sql. My server-side program exposes to the clent an interface that provides methods of reading from and writing to my SQL Server DB.
But when the client writes some date into DB, perhabs waites some time, and then tries to read that data from DB, it seems like no data has been written to DB, but if I restart my server-side app or perform DB detaching and reataching or restarting of sqlserver-service, then my client-side program can get that data from server-side program.
Does anyone have any idea what's wrong with my app (server?) and how to fix this?
UPDATE: I'm using Linq2Sql (calling CataContext.SubmitChanges()).
UPDATE 2: I've discovered, than if I add some new rows into my table, all is correct, but when I'm updating some pieces of row (some properties of objects) and then save changes, the changes become displayed only after reconnection to DB. It appears not to have flushed data immediatly after updating some properties and invocation of DataContext.SubmitChanges().
I don't have an answer, but some ideas for how to further track down the issue.
How do you write to the DB? Do you use transactions, that maybe remain open? Can you query
the updates in the database when they don't show up in your WCF response? Does your update maintain locks and somehow not release them? Did you eliminate caching as the cause?
Try remote-debugging to find out what happens on the server. A WCF trace might be helpful, too.