Notify Blazor + EF Core server when a db table is externallly changed? - entity-framework-core

I have a EF Core + Blazor client/server application where a table in an sql database may be updated by an external service. The server keeps a copy of that table and should react to changes to the original table (the application needs a copy for reasons). The external service may add, delete or modify records or even write the entire table from scratch, dropping the old table in the process.
Is there a way to have the server be notified whenever that external table is changed, similar to a DB trigger? Or is there a way to have a DB trigger notify the server so that I can process the notification in code in the server?

Related

How to set up 2-way syncing between Airtable base and multiple external sources

Is this even possible? I would like to update my companies external postgres database, as well as potentially updating their information in Salesforce, whenever a new record is added in Airtable.
I'd also like to set up a sync so that updates in the postgres database(and again Salesforce possibly) are reflected in Airtable.

EF Core with SQL Server persistence requires VIEW SERVER STATE permissions?

If I use EF Core against SQL Server, and the user account on the connection does not have permissions for VIEW SERVER STATE on object 'server', database 'master', the operation will fail with a DBUpdateException stating that this permission is missing.
What is EF Core trying to do that requires this permission? Is there any way for me to disable whatever it is doing that requires it? or do I have to add this permission?
Check if there is any access to the tables like sys.dm_tran_active_transactions, sys.dm_tran_current_transaction when you do the save changes in EF. Maybe it could be through a table trigger. I faced a similar issue due to a trigger trying to access those sys tables.

PostgreSQL - Periodically copying data from one database to another

I'm trying to set up an architecture with 2 databases, say preview and live, that have the exact same schemas. The use case is that edits can be made to the preview database and then pushed to the live database after they are vetted and approved. The production application would read from the live database.
What would be the most appropriate way to push all data from the preview database to the live database without bringing the live database down? Ideally the copy from preview to live would be an atomic transaction.
I've worked with this type of setup in MSSQL, but I'm fairly new to Postgres. So I'm open to hearing other ways to architect this (with Schemas perhaps?).
EDIT: The main reason to use separate databases is that I may need more than 1 target database (not just a single "live" database). I also may need to switch target databases on the fly without altering the source database schema.
I think what you're looking for is a "hot standby". This would be a separate instance of Postgresql, possibly on the same server but usually not, which is a near-real-time replica of the primary server.
In broad strokes, this is done by shipping the binary transaction logs from the primary server to the backup server, and then "replaying" them there. The exact mechanism for transmitting the logs may vary depending on your requirements.
Fortunately, the docs on this are excellent:
https://www.postgresql.org/docs/9.3/static/warm-standby.html
https://www.postgresql.org/docs/9.0/static/hot-standby.html

MS sync framework 2.1 - Delete on client without affecting server

I am using the Sync framework 2.1 to sync multiple SQL Express databases to a central database server over a WCF service. It works fine. Now I have a requirement that certain records in a table in the client database (source) which is set to "upload only" need to be deleted as part of archiving but it should not delete the corresponding records on the server (destination). Please note that the records would already have been synced. How can I do this with the Sync framework, like restrict the sync only for new records and deletes should not be synced. Is this possible?
Thanks.
that should be possible, you can intercept the changes from the source on the Changes Selected event and remove the rows you don't want to sync to prevent them from flowing thru the destination.
have a look at this post : Manipulating Change Dataset in SyncFx

Core Data syncronization procedure with Web service

I'm developing an application that needs to be syncronized with remote database. The database is connected to the a web-based application that user able to modify some records on the web page.(add/remove/modify) User also able to modify the same records in mobile application. So each side (server - client) must be keep the SAME latest records when an user press the sync button in mobile app. Communication between server and client is provided by Web Serives.(SOAP) and i am not able to change it because of it is strict requirements. (i know this is the worst way that can be used). And another requirement is the clients are not able to delete the server records.
I already be familiar with communicating web service (NSURLConnection), receiving data (NSData) and parsing it. But i could not figure out how the syncronization procedure should be. I have already read this answer which about how i can modify server and client sides with some extra attributes (last_updated_date and is_sync)
Then i could imagine to solve the issue like:
As a first step, client keeps try to modify the server records with sending unsyncronized ones. New recoords are directly added into DB but modified records shoud be compared depending on last_updated_date. At the end of this step, server has the latest data.
But the problem is how can manage to modify the records in mobile app. I thought it in a two way:
is the dummiest way that create a new MOC, download all records into this and change with existing one.
is the getting all modified records which are not in client side, import them into a new MOC and combine these two. But in this point i have some concerns like
There could be two items which are replicated (old version - updated version)
Deleted items could be still located in the main MOCs.
I have to connect multiple relationships among the MOCs. (the new record could have more than 4 relationships with old records)
So i guess you guys can help me to have another ideas which is the best ??
Syncing data is a non-trivial task.
There are several levels of synchronization. Based on your question I am guessing you just need to push changes back to a server. In that case I would suggest catching it during the -save: of the NSManagedObjectContext. Just before the -save: you can query the NSManagedObjectContext and ask it for what objects have been created, updated and deleted. From there you can build a query to post back to your web service.
Dealing with merges, however, is far more complicated and I suggest you deal with them on the server.
As for your relationship question; I suggest you open a second question for that so that there is no confusion.
Update
Once the server has finished the merge it pushes the new "truth" to the client. The client should take these updated records and merge them into its own changes. This merge is fairly simple:
Look for an existing record using a uniqueID.
If the record exists then update it.
If the record does not exist then create it.
Ignoring performance for the moment, this is fairly straight forward:
Set up a loop over the new data coming in.
Set up a NSPredicate to identify the record to be updated/created.
Run your fetch request.
If the record exists update it.
If it doesn't then create it.
Once you get this working with a full round trip then you can start looking at performance, etc. Step one is to get it to work :)