简体   繁体   中英

local and remote database in Windows Store app

I am working on a Windows 8.1 app which should work offline and online and it should connect to a database in both of the situation . So which kind of service or database I should implement to allow access to local and remote database and sync when it goes online.

There's not much tooling available to help you in your scenario. You can probably get the most out of Microsoft Sync framework , but you need to bear in mind that there's no official support for WinRT from Microsoft, nor is the framework further developed in its current form.

I suggest you take a look at SyncWinRT which is an open source library that can be used together with Microsoft Sync framework to make it work on Windows Phone and Windows Store apps. It's not all that easy to setup (neither is Sync framework itself) and there are some limitations, but depending on your requirements it might work for you.

Taking a broader look at your situation, there are 3 approaches which you can take:

  1. Have your application work directly with the remote database when online and with local database when offline, but make it work the same in both scenarios otherwise: this is the most tricky to do, because you need to be able to switch between the two DALs (data access layers) based on the mode and also be able to sync your local database with the remote one when you get back online. For switching the DALs you might want to take a look at CSLA.NET which in general has such capabilities, but its learning curve is quite high. For synchronizing the two databases the above mentioned SyncWinRT should work for you.

  2. Have your application always work with the local database copy which you synchronize with the remote one on user request: in this case you would have the same data structure locally as it is remotely, but your local business logic would always use the local database. This way you only need one DAL and the user can synchronize the data when he is online. Again for the synchronization you could use SyncWinRT , the rest will just be a standard app with local SQLite database which you can develop as you see fit.

  3. Have custom local data structure and synchronization process: completely customize the mobile experience by giving control of data synchronization to the user. He should be aware what data he is synchronizing when preparring for the offline work and synchronize that data back when he is done. The local data structure can be tailored for this and the synchronization will have to be done completely manually, but you can make it more simple if you control the actual use cases.

In my experience the last option usually works best both for users and for the developers. Although it seems to be more work, you can avoid a lot of conflicting scenarios by having closer control over the user options. And even the users might like the simpler wizard like experience better than a copy of their original online one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM