I have an application used by many users at the same time.
I use Entity Framework to communicate with a PostgreSQL database running on a server.
The problem is when an user does an insert on the database, the other users will not see the change.
How can I refresh entities when a change is done on the database automatically?
Thanks
There is nothing in EF to do any kind of push notification from the DB.
However that doesn't mean you cant have real-time updates in your UI. Your database is simply a storage bucket, what you will want to do is to send out a notification when you write to your database.
If you are working with a web app something like signalR is good, Below is a little psudocode on how you might do that
context.Things.Add(newThing);
context.SaveChanges();
hubContext.Clients.All().newThingAdded(newThing);
There are many different types of notification techniques, and it depends a lot on the application you are writing which you should use.
Thank you for your answers, I consider this question resolved.
I'll use a background worker to refresh some controls of my UI.
I think an auto-updater system will be too long to implement and my project comes to the deadline.
Related
I am trying to write a programmatic approach using C# to automatically update the Entities on the Power Apps Portal.The data source for entities can be a simple excel sheet or a SQL DB. Can some one please guide me through the quick steps i need to follow to accomplish this task.
Thanks in advance!
Microsoft decided handling cache was quite difficult, so they just base refresh the cache after a period of time now.
That being said, it's plausible they still refresh the cache on publish of the entity like they used to.
You could test this easily by making a change to a record, publishing customisations for the entity and seeing if now the change is reflected in the portal.
If that works you could try a jamming in some code to programatically publish customisation's to an entity:
https://learn.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/customize-dev/publish-customizations
I have local Access database on my computer. The database is used by another application. I want to write a windows service using .net to send an sms when changes have occurred in the local Access database.
Not sure how complex the application is and how often data changes, but You could use FileSystemWatcher to detect the moment when Access Data file has changed, then use some simple logic to check if table of interest is updated, for example look at row count in simplest case.
there is no efficient way for the service to know if the database changed and know which are the changes, why not write a method in the other app to send the sms?
i'm assuming that the other application is developed by you, if that not the case, please give more context to your question so we can help you.
Another possible solution is to use Quartz.net to schedule a job that executes a job every n minutes and runs a query against the database to evaluate if records changed in specific table(s).
I have used TopShelf and Quartz.net to build similar solutions and it works reliably. Here is a good tutorial to get you started: https://prashantbrall.wordpress.com/tag/topshelf/
I am new to this concept so i need guidance that what will be best to use in following scenario.
I have to make a desktop application that contains many features like parts Stock ,Employees Data,Company Cars Data etc etc.
now the problem is that many users would be using the application and offices situated are in different cities in which this application is installed.
I want a scheme that if one uploads any data to database other gets its reflection and other instantly gets updated.for example if more cars are added everyone using gets their cars list updated.
I was having idea to use webservices and data should be stored somewhere on website database so that everyone's application refreshes lists every say 20 seconds or so.
Any help is appreciated
You wouldn't reload all your data constantly; there are a couple of common approaches here:
keep a list of changes; if you add new data you add the primary data record and you write the fact that the change happened (essentially an "events" list). Then you can query the change log periodically to get and additions/updates/deletes simply by asking for all events after (x)
if the infrastructure allows, some kind of pub/sub framework - same approach really but typically using middleware for the changes, rather than the main DB
re how you get the data; polling is simple and effective; active pushing is harder to setup but may reduce latency - not sure it is worth it here
Another approach, though, is to design it as a web app - then all your data lives at the server-farm and is trivial to update immediately. Your "desktop" app could be a web page using ajax
Try Cloud Computing and store your data into cloud
OK trying to recover my points here after the downvote.
The cloud (windows Azure especially) is a great fit for this project. Web services would help too as they can be easily scaled out to a number of webservers (Instances in Azure speak). Having many desktop clients talking directly to a database is not a good idea and often results in scalability issues.
Output cacheing could help a great deal here if you are refreshing your client side data frequently, this can be implemented with almost no code. This makes it much easier to do than managing lists of changes.
I am using MySQL with C# / Visual Studio 2008. I need to know any method so that if one user updates the database, all the logged in users over the network, are notified that a change has been occurred.
If i logged in the database through my application, at that time the serial no of the latest record in the database was 10, and then i someone with the privileges updates the record in the database and at the same time i am being notified that the database has been updated with a new record.
Common example can be of MSN messenger's alert for a friend when he gets online...
Though i really don't want that popup, but alert functionality is something like that...
One more thing to ask:
I want a functionality like if a record's status is not updated (for say about more than 3 hours), then i want all users to get alert about that issue also. This functionality is needed for all of the records, not specifically for new records.
Quite a long answer, but your best bet would be something like SqlCacheDependency.
Also you could use something called the "Reverse AJAX" technique, which is used by Google Mail notifications, and talked about here: How does incoming mail notification on Gmail works?
Besides those two, your own other options AFAIK is simple server polling.
Also, you haven't mentioned what your client is.
Is it a public web site on the internet? Is it an intranet app, it is a WPF app?
If it's a web site, you're best best is client-side callbacks using the Reverse AJAX technique i mentioned.
You probably need to design some kind of poll functionality in your client. For example, you can send a request each minute asking the database "Have you updated anything since [date the client latest got updates]?" If the database answers true, you let the client request the full set of updates. If not, you let it sleep another minute.
Using the SqlDependency Class is a better way to make all your data driven more faster and efficient. It just remove the need of constantly re-query your database checking every time when a changes is made in the data.
I have a client who has a product-based website with hundreds of static product pages that are generated by Microsoft Access reports and pushed up to the ISP via FTP (it is an old design). We are thinking about getting a little more sophisticated and creating a data-driven website, probably using ASP.NET MVC.
Here's my question. Since this is a very small business (a handful of employees), I'd like to avoid enterprise patterns like web services if I can. How does one push updated product information to the website, batch-style? In a SQL Server environment, you can't just push up a new copy of the database, can you?
Clarification: The client already has a system at his facility where he keeps all of his product information and specifications. I would like to refresh the database at the ISP with this information.
You don't mention what exactly the data source is, but the implication is that it's not already in SQL Server. If that's the case, have a look at SSIS.
If the source data is in SQL Server, then I think you'd want to be looking at either transactional replication or log shipping to sync the two databases.
If you are modernizing, and it is a handful of employees, why would you push the product info out batch style?
I don't know exactly what you mean by "data driven", but why not allow the ASP.NET app to query the SQL Server product catalog database directly? Why generate static pages at all?
UPDATE: ok, I see, the real question is, how to update the SQL database running at the ISP.
You create an admin panel so the client can edit the data directly on the server. It is perfectly reasonable to have the client keep all their records on the server as long as the server is backed up nightly. Many cloud and virtual services offer easy ways to do replicated backups.
The additional benefit of this model is that more than one user can be adding or updating records at a time, making the workforce a lot more scalable. Likewise, the users can log in from anywhere they have a web browser to add new records, fix mistakes made in old records, etc.
EDIT: This approach assumes you can convince the client to abandon their current data entry system in favor of a centralized web-based management panel. Even if this isn't the case, the SQL database can be hosted on the server and the client's application could be made to talk to that so you're only ever using one database. From the sounds of it, it's a set of Access forms and macros which you should have source access to.
Assuming that there is no way to sync the data directly between your legacy system DB (is it in Access, or is Access just running the reports) and the SQL Server DB on the website (I'm not aware of any):
The problem with "pushing" the data directly into the SQL server will be that "old" (already in the DB) records won't be updated, but instead removed and then recreated. This is a big problem with foreign keys. Plus, I really don't like the idea of giving the client any access to the db at all.
So considering that, I find that the best is to write a relatively simple page that takes an uploaded file and updates the database. The file will likely be CSV, possibly XML. After a few iterations of writing these pages over the years, here's what I've come up with:
Show file upload box.
On next page load, save file to temp location
Loop through each line (element in XML) and validate all the data. Foreign keys, especially, but also business validations. You can also validate that the header row exists, etc. Don't update the database.
3a. If invalid data exists, save an error message to an array
At the end of the looping, show the view.
4a. If there were errors, show the list of error messages and tell them to re-upload the file.
4b. If there were no errors, create a link that has the file location from #2 and a confirmation flag
After the file location and confirm flag have been submitted run the loop in #3 again, but there's an if (confirmed) {} statement that actually makes the updates to the db.
EDIT: I saw your other post. One of the assumptions I made is that the databases won't be the same. ie, the legacy app will have a table or two. Maybe just products. But the new app will have orders, products, categories, etc, etc. This will complicate "just uploading the file".
Why do you need to push anything?
You just need to create a product management portion of the webpage and a secondly a public facing portion of the webpage. Both portions would touch the same SqlServer database.
.Net has the ability to monitor a database and check for updates. then you can run a query to [push] the data elsewhere.
or use sql to push the data with a trigger on the table(s) in question.
Is this what you were looking for?
You can try Dynamic Data Web Application.
You should have a service that regularly updates the data in the target DB. It will probably run on your source data machine (where the Access-DB is)
The service can use SSIS or ADO.NET to write the data. You can do this over the web, because you have access via TCP/IP to the server I assume.
Please check when the updates are done and how long it takes. If you can do the updates during the night you are fine. If not you should check, if you can still access the web during the import. That is sometimes not the case.
Use wget to push the new data file to the mvc app and once the data is received by the action, the mvc app invokes the processing/importing of the data (maybe in a worker process if you dont want long requests).