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

Asked

Viewed 982 times

7

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

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

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

Thanks in advance.

1 answer

2

At first I see two possible solutions to this: Signaler and Masstransit. In both cases, you will need an application to run on a server (it may be the same as the database), in case Masstransit could be a windows service, in case Signalr could a Web API. I’ll talk about Signalr, but since your question here is more about whether it is possible to do this (and not how to completely configure Signalr and put it to work), I will just give you the steps and provide some links for you to study and mature the idea.


Create a new ASP.NET MVC project, install the library from Signaler on it, configure the necessary 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 (e.g.: NotificaAlteracao()) and then, as necessary, create more.

If possible, I suggest you take some time to get a good read at that link.

Then install the libraries from the C# client to Signalr in the client application, and configure it to connect to the server, also configuring the proxies with the necessary hubs. To install the client library, run the following command:

Install-Package Microsoft.AspNet.SignalR.Client

Then configure the methods in your client to capture the events of the hubs, and in them you make the necessary update.

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

Hence you will need to identify all points that make changes to the database and trigger an event in the server Signalr, and the server will propagate these events to the clients (depending on how it is implemented, including for the very client who triggered the event).


In the future, you may think about creating Web Apis in its web application (which is on the server), so that it communicates with the database, and its client applications would only call the Apis instead of accessing the database directly.

The link guide I gave you is very complete, and at first it seems to be complicated. but in fact it is not very secret, it is very simple. The problem is if you do not have access to the server of the database in question to install a web application, or even have no experience to publish web applications, but otherwise it is quiet.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.