vendredi 17 juillet 2015

Android connect to MS SQL 2008 and Syncing (SQLite) with multiple users

I am working on an application for Android using Android Studio which uses MS SQL 2008 for the external database and SQLite for the internal local database.

I currently have the app all setup to work with the internal SQLite database, however I know need to start considering how I can Sync this to the database without overwriting any newer data, I have added the Android Sync Adapter to my code, however really not sure how I can use this to now sync and connected my SQlite db to my MS SQL 2008 db.

A little context on the app that I am working on, its a management app, which can be used by multiple users and multiple teams. All this data is saved into the MS SQL 2008 Server and only the relevant data for the team user is stored on the phone itself. The idea is that when the user updates any data it is saved to both the SQLite and MS SQL db, however I need to keep in mind that internet connection may not be available (so I plan on setting a flag in the local database id the MS SQL upload fails).

Below are my question, any further guidance, advice or tutorials would be much appreciated:

1 - How can I connect my android device to MS SQL Server 2008 2 - What is the best way to sync my data always keeping both DBs up to date

Example of how the app could work:

SQL Server 2008

  • SQLite (Team 1) - Total 3 users syncing data at the same time
  • SQLite (Team 2) - Total 8 users syncing data at the same time

As mentioned the idea is to use a unique teamId and then a incremental id for say the userId -> therefore the key would be both the teamId and userId. This however may not work if 2 admin users are adding a new user at the same time as both the teamId and userId would end up being the same (although this is more a side issue to my above 2 questions).

Finally, I don't necessarily require auto-syncing as I can manually trigger this in the relevant places and need to partially consider the fact that this app will also be created on iOS which will be using the same Ms SQL server and SQLite db, therefore would ideally like to maximise code re-use, again not essential as the Android version is priority.

Aucun commentaire:

Enregistrer un commentaire