Notify for database change - c#

I have 2 systems and it is lan based. I just want the other system to be notified when there's a change in the database. I am using C# and ms-access for the database. Can you please give me some ideas on how to do it? Thanks in advance!

If you are using access, you can't write triggers as you could in MS SQL for example. There are different approachs. Some of them are:
On system 1, develop small web api with a method which will return true or false if system was changed. From system 2 ping system 1 API method on some interval.
Use SignalR, Microsoft technology for real time programming. Create SignalR client on system 2, and send message from system 1 to system 2 when change on database occures.

If you change your database only from client (C# application) then it would be more appropriate to send the notification from your client (when changing data) rather than using a push model (e.g. trigger callback from database).
See the StackExchange question.

Related

Real time activity monitoring for a Windows service

I have a Windows service that currently outputs logging activity to either a text file or a database (depending on the activity). What I would like to do is to have a way to run another process (probably an executable) that can connect to that service and receive activity updates from that Windows service using like a publish/subcribe approach.
In theory, I guess this can be done by hosting a socket connection on the Windows service and pushing activity data as it happens. I wonder though if there is s better approach? Is there maybe a framework that can do all this for me easily? Or maybe I should use a MQ product to broadcast the application activity?
I am using C# .net version 4.5
There are several ways:
Socket is very good two-way communication
WCF is also another option, also two way communication support
Database - if you need to keep the history of the signals, you probably use one table where server/host inserts into a table and client reads from table using SQL Dependency. You can read new signals without timer or waiting, almost in real time.
Another good option is SignalR.
I have been using all technologies except WCF.

C# - need a client - server application to share files between multiple clients - ready-made solution?

I'm developing a C# application which needs to use some kind of a database to store information. Unfortunately no DB systems such as MySQL are available so I'm limited to basic IO operations and text files. The application will run on multiple machines and all instances need access to the very same data. The solution/idea I've come up with so far is as follows:
Client requests file from server
Server sends the file to the client
Client makes changes, sends back
Server checks if in the meantime the same file was modified by another client. If yes, receive the file from the current client and merge. If not, simply replace the server's copy with the client's one
Question is: is there any ready made solution for this? Maybe I could use a framework?
If not and I have to do it myself, are there any recommendations you could give me?
Thanks in advance.

Async notification when another application changes the database with entity framework 4.1 and DBContext

I have a REST web service that is used for comunication with multiple clients, some sort of chat, but I have to make all the changes into the database as soon as the clients comunicate something and then inform all the others clients when a change is made.
I basically get a POST request and I have to reply as soon as an entry is mofified.
Now I make my thread sleep 1 second and then keep recreating the context every second for each request and if there are changes to the database I send the response.
This looks ugly to me and I wonder if there is some event or async method to be notified when a specific entry in the database is modified?
Thank you Advance.
If you're using MS SQL Server, you might have success with using Sql Dependencies. Here's a link to a brief tutorial: C# & SqlDependency - Monitoring your database for data changes.
Microsoft's successor to Notification Services, SQL Server 2008 R2 – Complex Event Processing (CEP) Technology might also serve your purposes, but I know nothing about it but what's on the web page.

LAN Application

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.
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.
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.
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.

How to notify user of new message?

I need to update the user's messages when a new one was sent to him.
I know that I can create a SQL Trigger and get it using CLR Triggers.
But how do I notify the user without having some method polling to see if something's changed?
How do I know that I have new messages without check the database every time?
It's 100% similar to an email system or the facebook message system.
One user will send a message to another, how to get that new message without having a method checking the database for changes from time to time?
I'm using SQL Server 2008 and ASP.NET MVC3.
Thanks.
Please take a look at the SignalR (https://github.com/SignalR). You'd have to perform tests on how it behaves in your environment.

Categories