Updating application (C #) in real time with the Database (Mysql)

7

I'm creating a client server application, the application would run on multiple machines using the same database (mysql) on an online server.

I would like as soon as the data in a table were changed, inserted or even deleted, the other applications running were updated instantly. I currently use a timer that performs a check every 3 seconds, however I end up making unnecessary requests.

Is there a way to do this? Hearing that the trigger would be possible, but how would it work? How do I get the trigger to return something in the application as soon as a data is entered, without the need for a DML command to check if something has changed.

Thank you in advance.

    
asked by anonymous 20.05.2017 / 07:31

1 answer

2

On the face of it, I see two possible solutions to this: SignalR and MassTransit . In both cases you will need an application to run on a server (can be the same as the database), in case MassTransit could be a windows service, in the case the SignalR could a Web API. I'll talk about SignalR, but as your question here is more to know if it's possible to do this (and not how to completely configure SignalR and put it to work), I'll just take the steps and provide some links for you to study and mature the idea .

Create a new ASP.NET MVC project, install the SignalR library on it, configure the required Hubs, and publish to the server's IIS. One idea would be to create a Hub per table, and create the methods as you see fit. To test, you could start with a simple (ex: NotificaAlteracao() ) and then as needed create more.

  

If possible, I suggest you take the time to give a good read    on this link .

Next, install the C # client libraries for the SignalR in the client application, and configure it to connect to the server, also configuring the proxies with the required hubs. To install the client library, run the following command:

Install-Package Microsoft.AspNet.SignalR.Client

Then configure the methods on your client to capture the events from the hubs, and then make the necessary updates on them.

  

For more details regarding the C # client application, see in this   link .

From there you will need to identify all the points that make changes in the database and trigger an event in the SignalR of the server, and the server will propagate these events to the clients (depending on how it is implemented, fired the event).

In the future, you can think about creating Web APIs in your web application (which stays on the server), so that it communicates with the database, and your client applications would only call APIs rather than accessing the database directly.

The guide to the links I've given you is very complete, and at first it seems to be complicated. but it does not really have much secret, it's very simple. The problem is if you do not have access to the database server in question to install a web application, or even have no experience to publish web applications, but otherwise it is quiet.

    
21.05.2017 / 05:01