SQLiteSync



Note:
This topic is applicable only for full .NET Framework.
  1. Sqlite Sync Data
  2. Sqlite Sync With Mysql
SQLiteSync

Microsoft Sync Framework is a data synchronization platform, allowing data synchronization between any applications, services or devices regardless of the network used and data source type. To allow data source agnostic synchronization, Sync Framework uses synchronization providers for connecting to each of the data sources. Sync Framework database synchronization providers, similar to ADO.NET providers, allow other Sync Framework components to work without the need to concern on the underlying database implementation.

Note that Sync Framework is supported only in the Professional Edition of dotConnect for SQLite.

  • Database Provisioning
  • Synchronization
  • Database Deprovisioning

Jan 27, 2015 - SQLITE-SYNC. They seem to have a free version - SQLite to MSSQL Synchronization. Thiss one needs to be licensed On the other hand perhaps you could consider using SQL Server on both ends? This would make the synchronization far more easy. GitHub - sqlite-sync/SQLite-sync.com: AMPLI-SYNC is a framework for synchronizing data between a Sqlite database and an MS SQL/MySQL/Oracle/PostgreSQL database. With this framework your application can work completely offline (Airplane Mode), then perform an automated Bidirectional Synchronization when an internet connection becomes available.

Open ODBC Data Source Administrator in your environment. Click the system DSN tab and click 'Add' Select the SQLite ODBC connector you installed and give the connection a meaningful name, for example, sqlitemigrationsource Set the database name to the.db file. Microsoft.Data.Sqlite overview.; 2 minutes to read; b; D; m; In this article. Microsoft.Data.Sqlite is a lightweight ADO.NET provider for SQLite. The Entity Framework Core provider for SQLite is built on top of this library.

Sync Framework Support Overview

Sync Framework architecture allows clients both to synchronize data via the central server or to exchange data directly. The following main classes are used for data synchronization:

  • SyncOrchestrator - creates and manages synchronization sessions. This class is provided by Sync Framework.
  • DbSyncProvider - implements the synchronization service for interaction with a database and shields SyncOrchestrator from the specific implementation of the database. dotConnect for SQLite provides its own SQLiteSyncProvider class implementation for SQLite database.
  • DbSyncAdapter - maintains the interaction between the DbSyncProvider and the database. This class is provided by Sync Framework.

To include database data to synchronization, first you need to provision the database. Provisioning means the creation of Sync Framework auxiliary tables, stored procedures, functions, and triggers for tracking data changes in the specified synchronization scope - a table or a group of tables to synchronize data from. Both databases being synchronized must be provisioned in order to synchronise data.

SQLiteSyncScopeProvisioning is the key class for performing database provisioning. It allows provisioning a synchronization scope. We will describe the provisioning and synchronization scopes in more details in our tutorial below.

After the provisioning, the databases can be synchronised. When synchronizing databases, you may retrieve synchronization operation statistics. It includes the time synchronization took, the number of processed changes and failed changes.

In case there is no need to synchronise a database or any specific scope any more, the database (or scope) can be deprovisioned. This means deleting of the unneeded Sync Framework database objects and/or data. User tables and data are retained. dotConnect for SQLite offers the SQLiteSyncScopeDeprovisioning class for scope deprovisioning.

The parent class of the SQLiteSyncProvider class is the descendant of the standard Sync Framework DbSyncProvider class. Other synchronization classes of dotConnect for SQLite are not inherited from the standard Sync Framework classes, but provide the same interface.

Sample Application

For this tutorial you need Visual Studio 2008 or higher, and Sync Framework 2.1.

In our tutorial we will synchronize two databases with identical structure. Let's call them the development database and the production database. We will use a simple database of one table 'Product' for our tutorial. Here is its script:

If you want to configure data synchronization for a new database, and its tables are not created yet, they can be automatically generated during the provisioning. However, in our tutorial we will create them manually.

Create a new console application in Visual Studio. It could be any other project type as well, but for simplicity's sake we'll use console project throughout the tutorial.

Add the references to the following assemblies to your project:

  • Devart.Data.Synchronization
  • Devart.Data.SQLite.Synchronization
  • Microsoft.Synchronization Version 2.1
  • Microsoft.Synchronization.Data Version 3.1
  • Devart.Data.SQLite

Database Provisioning

The first step of the synchronization is database provisioning. We will start from the development database and demonstrate different provisioning scenarios. Provisioning includes defining the synchronization scope and creating the necessary database objects.

The synchronization scope is one or more tables (with the specified columns to synchronize) that will be synchronized as a whole. The synchronization scope can include all columns in a table or just a subset of them. It can include all rows or only the rows that match some filter condition. You also can create a template for filters (a condition including a variable), and then create multiple synchronization scopes using filters based on this template.

When creating a synchronization scope, you must create descriptions for the tables of this scope. The synchronization scope tables can either already exist in the database, or they be created during the database provisioning based on their descriptions.

Creating Synchronization Scope without Filter

You can create table descriptions in two ways. The first way is to create the description manually, and the second is to use the SQLiteSyncDescriptionBuilder class to generate the description based on an existing database table. Since the tables are already created, we will use the second option.

Add the following code to the Main method:

Visual BasicCopy Code

After executing this code, Sync Framework creates the following database objects in the database:

  • schema_version table - contains the information on the version of Sync Framework that provisioned the database.
  • scope_info table - contains the list of all the provisioned scopes.
  • scope_config table - contains scope configuration information.
  • products_tracking the table with metadata of the provisioned table 'products'.
  • Insert/update/delete triggers for tracking changes in the provisioned table.

Creating Synchronization Scope with Filter

Now we will demonstrate creating synchronization scope with a filter. The filter is just a SQL WHERE condition that allows synchronizing not all the data of a table, but only the rows that meets certain condition.

The following code creates the synchronization scope with the filter.

Visual BasicCopy Code

The AddFilterColumn call specifies the column from the provisioned table, that will be used in the filter and must be added to the tracking table. FilterClause specifies the condition. Note that we use the alias t when specifying the condition. This alias refers to the tracking table.

After this code is executed, the specified filter column is added to the products_tracking tracking table. An updated products_insert trigger will set values to this column.

Creating Synchronization Scope with Filter Based on Template

Creating a filter template is similar to creating a synchronization scope with a filter. The difference is that the filter condition uses a parameter instead of value. You can then create multiple synchronization scopes based on this template by supplying a value that will substitute this parameter in the filter condition. The template itself cannot be used for synchronization.

For example, in our tutorial we will create an IsAvailableTemplate template with the condition 't.Available = f_Available' where f_Available is a parameter of a boolean type. We will create two synchronization scopes by providing values for this parameter. They will be the AvailableScope scope with f_Available = true and NotAvailableScope with f_Available = false.

Here is the code for creating the template:

Visual BasicCopy Code

And now let's create synchronization scopes based on the template. To create such scope, you need to call the PopulateFromTemplate method and pass the new scope name, the name of the template, and the value of the filter parameter to it.

Visual BasicCopy Code

The code for creating the NotAvaibleScope is almost the same, just change the scope name and the filter parameter value.

Creating Synchronization Scope with Subset of Columns of Existing Table

Here is an example of creating synchronization scope for synchronizing data in only a subset of table columns.

Visual BasicCopy Code

Synchronization

To synchronize databases you need first to provision the Production database, and then to actually synchronize the databases.

Sqlite sync databases

Provisioning Production Database

When provisioning the production database, the DbSyncScopeDescription class is used to specify the synchronization scope name and tables to synchronize. The latter can be either specified explicitly or retrieved from the already provisioned development database.

Visual BasicCopy Code

Synchronization

Synchronization is performed via the SyncOrchestrator class. You need to assign the synchronization provider instances to its RemoteProvider and LocalProvider properties and then run its Synchronize method.

Visual BasicCopy Code

Database Deprovisioning

When deprovisioning the database, the objects, created by Sync Framework, that are not used any more are deleted. If there is at least one scope that still uses these objects, they will not be deleted. User database objects are not deleted at all. You can deprovision a provisioned scope, a template with all scopes built on it, or the whole database.

Deprovisioning Synchronization Scope

To deprovision a single synchronization scope you need to create a SQLiteSyncScopeDeprovisioning object and execute its DeprovisionScope method, which accepts the scope name as its parameter.

Deprovisioning Template

Template deprovisioning deletes the template and all the synchronization scopes, based on this template. The DeprovisionTemplate method of SQLiteSyncScopeDeprovisioning is used to deprovision a template.
Visual BasicCopy Code

Deprovisioning Storage

Sqlite Sync Data

Storage deprovisioning removes all the templates, synchronization scopes, and all the Sync Framework database objects in the connection schema. The DeprovisionStore method is used for storage deprovisioning.

See Also

Sqlite Sync With Mysql

Entity Framework section | Entity Framework Support Overview