X
logo
Master your Data
21 May 2008

2-Way List Sync SQL Server <-> SharePoint

Data Synchronization Studio supports 2 Way Synchronisation of data between SQL Server and SharePoint if you follow a couple of guidelines.

The main thing to consider is to use a GUID (uniqueidentifier) as the Primary Key (Unique Constraint) and if you call this column DSID then the Mapping will be easier.

Step 1 is to create a Table in your database that follows this schema like below.

CREATE TABLE [dbo].[ProductList] (
    [DSID] uniqueidentifier DEFAULT(newid()) NOT NULL,
    [CompanyName] nvarchar(40) NOT NULL,
    [ProductName] nvarchar(40) NOT NULL,
    [CategoryName] nvarchar(15) NOT NULL,
    [QuantityPerUnit] nvarchar(50) NULL,
    [UnitPrice] decimal(18, 0) DEFAULT(0) NULL,
    [UnitsInStock] smallint DEFAULT(0) NULL,
    [UnitsOnOrder] smallint DEFAULT(0) NULL
)
GO
ALTER TABLE [dbo].[ProductList] ADD CONSTRAINT [PK_ProductList_2FE911D7] PRIMARY KEY CLUSTERED ([DSID] ASC)
GO

Step 2 is to fill your table with the Data you would like to Synchronize.

Step 3 You will then need to fire up Data Synchronization Studio and create a List in SharePoint that will map to this table this should look something like the picture below.

DataSync-1  

Important: You should have a Column DSID mapped to a SharePoint column DSID of type GUID and it should be marked as the Unique Column.

 

 

Step 4 Modify the Project File (*.dsprj) to support 2-way sync by default the 2-way sync is disabled to prevent accidental deletion of data.

Open the *.dsprj file in your favourite text editor (notepad.exe) and look for the Xml Element Project you should see an Attribute called SyncOption change this value to be SyncAandB.

So the Project Element should look like this.

<Project Name="" Version="" SyncOption="SyncAandB">

You can now drop the project file into the Synchronization Service project folder (C:\Windows\DataSyncProjects) and start the service. Now you can make changes in both SQL Server and SharePoint and the change will be replicated in each system.