Desktop application which can work offline when no connectivity with SQL Server

c# entity-framework entity-framework-6 sql-server wpf


I'm using Entity Framework Code First to construct and utilise a SQL Server database while creating a WPF desktop application. My database will be hosted on a single server and operate continuously.

I want to provide the ability to edit data without connecting to the SQL Server database and save it in some way. Additionally, all updates may be sent to the SQL Server database anytime your application establishes a connection with it.

Is there any way to achieve this by using Entity Framework ? I want to draw attention to the fact that I'm employing the format Enterprise Framework. Does EF have this kind of capability already? Or do I need to do it manually, such as writing it in any file system and then manually merging it into the database later on?

10/17/2016 11:42:07 PM

Accepted Answer

You may identify the precise exceptions that are thrown when the SQL Server connection is broken and include try-catch blocks in your calls. Pass the object to a method in your catch block that serialises it to JSON and stores it on the hard disc in a certain directory or whatever if the server is down. Check that directory to determine whether there are any stored entities that need to be saved on your subsequent successful query.

Don't use general catches; you don't want unrelated errors to cause this code to run.

Some factors to consider include the possibility that someone else may have altered the data since then. Do you plan to revoke those modifications? If you are offline, how did you get the data that has to be preserved in the first place?

10/14/2016 8:42:09 PM

Popular Answer


Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow