Quick Development and synchronization programs under Microsoft sync framework

Source: Internet
Author: User
Tags sql server express

From: http://www.mobpub.net/viewthread.php? Tid = 2380 & extra = Page % 3d6

Microsoft sync frameworks (MSF) is a comprehensive synchronization platform that supports online and offline synchronization of applications, services, and devices. MSF consists of the following components:
* Sync services for ADO. Net: Synchronize ADO. NET data.
* Sync services for feedsync: Synchronize RSS and atom Seeds
* Sync services for file systems: Synchronize files and folders
* Sync framework core runtime: a custom synchronization solution that supports native code.
This article describes how to quickly create a sync services for ADO. NET application for data synchronization. Since you can quickly create a synchronization program in the PC winform project using the wizard, This article first introduces the sync services for ado on the PC webform program.. NET development will introduce the development on mobile devices one after another, which is also my biggest concern.
Download and install
Go to the following link to download microsoft synchronization services for ADO. net. SQL ce 3.5 is required for Microsoft synchronization services for ADO. Net local cache data. SQL CE 3.0 is not supported. For the differences between SQL ce 3.5 and 3.0, see SQL ce compatibility issues under. Net campact framework.
Create a local database cache
First, create a winform program for the PC. Right-click the project to create a new item. After installing Microsoft synchronization services for ADO. net, the "local database cache" appears in the new Wizard. Select this type.

Download(46.35 KB)

This file establishes the synchronization relationship between the server and the local database. The server database supports ADO. net any database, I use free SQL Server Express, the local database is SQL ce 3.5, you do not need to manually create, the Wizard program automatically generate a local database based on server data. For how to download and install SQL Server Express, see SQL Server express and SQL Server compact.
Create a database named testdb on SQL Server express and create two tables with the following table structure:
Create Table [DBO]. [T1] (
[F1] [int] not null,
[F2] [nvarchar] (50) Collate SQL _latin1_general_cp1_ci_as not null,
Constraint [pk_t1] primary key clustered
(
[F1] ASC
) With (pad_index = OFF, ignore_dup_key = OFF) on [primary]
) On [primary]
Create Table [DBO]. [T2] (
[F1] [int] not null,
[F2] [datetime] not null,
Constraint [pk_t2] primary key clustered
(
[F1] ASC
) With (pad_index = OFF, ignore_dup_key = OFF) on [primary]
) On [primary]
Select Database
After configuring the database server, you can select "add" to add tables to be synchronized. In this example, select T1 and T2.

Download(39.19 KB)

If the data table belongs to the following conditions, it cannot be displayed for selection:
1. It is not the user's default schema ).
2. No primary key is defined.
3. The name must be longer than 118 characters.
4. The fields contain data types not supported by SQL ce 3.5.
By default, the wizard automatically adds lasteditdate and creationdate to the original table. Add a data table (former table name_tombstone ).
Add a data source (Dataset)
After adding a Data Synchronization table, the wizard automatically displays the add data source (Dataset) wizard, fill in the dataset name, select the table and field.

Download(26.29 KB)

The system automatically generates processing and data classes, as shown in figure

Download(19.91 KB)


Code Writing

Add the load event handler and a button and handler in the program. Add the following code:
Public partial class form1: Form
{
Testdbdataset = new testdbdataset ();
Testdbdatasettableadapters. t1tableadapter t1tableadapter = new testdbdatasettableadapters. t1tableadapter ();
Testdbdatasettableadapters. tableadaptermanager = new testdbdatasettableadapters. tableadaptermanager ();
Public form1 ()
{
Initializecomponent ();
}
Private void button#click (Object sender, eventargs E)
{
Tableadaptermanager. updateall (testdbdataset );
// Call syncagent. Synchronize () to initiate the synchronization process.
// Synchronization only updates the local database, not your project's data source.
Localdatache1syncagent syncagent = new localdatacache1syncagent ();
Microsoft. synchronization. Data. syncstatistics syncstats = syncagent. Synchronize ();
Testdbdataset. t1.merge (t1tableadapter. getdata ());
}
Private void form1_load (Object sender, eventargs E)
{
T1tableadapter. Fill (testdbdataset. T1 );
}
}
A program synchronized from the server to the local SQL CE is completed.
Testdbdataset: indicates a strong type of memory data cache.
T1tableadapter indicates the connection and commands used to fetch and store data.
Tableadaptermanager is used to update the association between tableadapters (hierarchical update ).
Test
Add some data to table T1 in SQL Server express as follows:

Download(9.43 KB)

Run the program and click synchronize.
Open the SQL ce database in vs2008 and you will find that the data in the SQL ce database is exactly the same as that in Table T1 in SQL Server Express.
Modify and delete the data in Table T1 in SQL Server express for further testing. You will also find that the SQL ce database synchronizes data on the server.

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.