I am creating a Android Application in Xamarin that uses Sqlite and I need the app to sync all the data from the sql server database to the sqlite database on the phone. Are there any good references for doing this as far as tutorials or examples? One thing to mention is the sqlite database for the phone would have the same schema as the server.
-
I would recommend taking a look into Azure Mobile Services and Mobile apps to handle this: github.com/jamesmontemagno/MyExpenses-Sync has a lot of good code and video content.– JamesMontemagnoOct 20, 2015 at 0:17
-
James I do have a question on that. Don't I have to pay for the azure service? The database I'm pulling from is hosted on my own network server.– yamsOct 20, 2015 at 1:08
1 Answer
The closest thing, within certain constraints is Azure Mobile Services with Offline Sync, but that uses it's own SQL Lite and SQL Server Instances, see https://azure.microsoft.com/en-gb/documentation/articles/mobile-services-windows-store-dotnet-get-started-offline-data/
If you are wanting to roll your own then you probably want to create your own Web Api in front of the SQL server to handle CRUD commands, and inititate that from within your app. We've done this, but there's no quick pointer, it all depends on where your 'master' data source is, how many clients, conflict management etc.
It's a huge topic
-
Well the server has to be our own. The two schemas match S could I just pre make the db on SQLite and have it match the server? Would that make it simpler?– yamsOct 20, 2015 at 12:37
-
Not really, you need 'something' a sync engine, or service to do all the work, the comparison between data, when last modified, when conflicted etc, and I don't think that really exists unless you create your own. Something like - sqlite-sync.com (But don't think that will wok in Xamarin unless you create your own bindings) Oct 21, 2015 at 13:28
-
-
You still need 'something' to do that, if it's one way then easier to do in code, but even then you have to identify which records have changed, are they inserts, updates, or deletes at the other end, and even then 'how' are you going to talk to the SQL Server - is it on the same network? If not you need to create a web api to expose it safely. Oct 21, 2015 at 14:19
-
2Well, at it's simplest, in my local sqllite table I'd add three fields isNew, isModified, and isDeleted, default to a value of 0 and then set to 1 when you add, edit, or delete a record. Then you need somethign that runs periodically, looks for any records with a value of 1 and use Restsharp or similar to POST, PUSH, or DELETE calls to your web api and send the data over. Then reset the values back to 0 once done Oct 21, 2015 at 14:33