Software Architecture and more...

Sync Services + N-Tier + Oracle + Conflict Detection

I've been following the Synchronization Services for a few months now, and I really liked what I saw.

One of the best places to get a head start in this technology is Rafik Robeal's site, SyncGuru. This site contains a lot of Sync Services demos, and provides a really good explanations and How-To's  for using the Sync Services advanced capabilities, such as N-Tier architecture, Conflicts Detection, and using Oracle as a backend database.

A few days ago I was invited by Oracle in Israel to present in an event called OracleWeek (Note: Hebrew site), and I wanted to demonstrate the most advanced capabilities of Sync Services. I wanted to be able to demonstrate:

- Oracle as a backend database (naturally...)

- Using N-Tier architecture (because most of the modern apps are built this way)

- Conflicts detection (because, after all, this is what really matters)

But I wanted all this in a single application.

So, after much work and some obstacles, I created the demo and presented it in the event. The feedback was quite positive,so I decided to upload the demo here, so everyone can see how this can be done.

So, here I am, proudly presenting the SNOC (take a look at the title, you'll understand...). The attached ZIP file contains the full SNOC demo, which demonstrates all the features mentioned above.

 

Demo Description

The demo simulates a typical scenario of a central database (Oracle Express) and two client applications. The communication between the client and the server is done via WCF using basic SOAP/HTTP protocol.

The demo allows the user to insert or update records (no support for deletes, sorry. Lack of time...), save them locally (into the SQL CE), and synchronize them with the server database. When a conflict is detected (the demo uses conflict detection on the client, not the server), an appropriate message is displayed, and the user can choose to overwrite the local values or abort the sync process.

This demo does by no means cover all the Sync Services goodies. Issues like deletes, transaction management, batch management, statistics, progress indicator and more are not demonstrated, but I believe it can still help to get a good idea of how this should work.

In addition, the code is far from perfect. It is not optimized, contains no minimal error checking and can definitely be built better. Its only purpose is to demonstrate the Sync Services features, and not coding best practices.

 

Software Prerequisites

Visual Studio 2008 RTM (Actually, this may work also in VS2005 with SQL CE and Sync Services installed, but I didn't try)

Oracle Express 10g (can be downloaded here)

 

Folders Description

There are 4 folders in the ZIP file:

OracleSyncDemo2 - Contains the master solution file and the source code of the client apps.

WebServiceFolder - Contains the project of the server side.

Demo2Clients - Contains two folders, each one containing a single exe and a config file. These exe's are exactly the same, and they simulate the two clients.

ClientDBBiDi - Contains the two SQL CE files, file for every client , pre-populated with the "customers" table.

 

Installation Instructions

1. Copy all the contents of the ZIP file to a folder in your hard drive.

2. Create a new user in Oracle. Call it whatever you want (I called mine "offlinesync").

3. In the Oracle admin site, log in as the new user.

3. Load the file offlinedemo.sql, found under "OracleSyncDemo2\OracleSyncDemo2\Setup", in the Oracle admin site. This file creates a "customers" table, and add some triggers to it in order to track the changes occurred to it.

4. In the web.config file, found under "WebServiceFolder\SyncWS", modify the "OracleExpress" connection string to point to your oracle database and user.

5. Open both the config files in the Demo2Clients folder. Note that:

- They have a different "ClientID" value (under appSettings). This is to differentiate them visually. This value is displayed in the window title.

- There is a single connection string which points to the local database location. Change the location to the folder in which you copied the two client databases.

- There is a service reference which points to http://localhost:1256/Service1.asmx. This shouldn't be a problem as the server project is set to use a fixed port.

OK, time to take off...

Usage Instructions

1. Open the OracleSyncDemo2.sln file found under "OracleSyncDemo2" folder. This should open Visual Studio 2008.

2. Note there are two projects in the solution. Make sure they are both successfully loaded.

3. Run the solution. Note that the solution is preconfigured to execute only the server side project. If everything is OK, you should see an IE window opens, pointing to the web service in the server project.

4. Execute both the executables in the Demo2Clients folder. If everything is all right, you should see something like that:

Two empty clients

5. Enter some data in the first row of "Client 1", move the cursor to the second row and click "Save Client Data". You should see the following:

Client 1 saved locally

Right now we inserted a new row to the local SQL CE of Client 1. You can create a new connection in Server Explorer pointing to this file to see it changes in live.

6. Click "Synchronize" in Client 1. The first time may take a few seconds. you should see a message box stating that 1 record was uploaded successfully. Note: You may see that the total changes updated is more than 1. I'm not sure why this happens and I need to dig into it more. It will happen on the first synchronization only.

This action uploaded the new row to the backend database. Again, it might be a good idea to create a new connection in Server Explorer which will point to the Oracle to make sure everything is fine.

7. Click "Synchronize" in Client 2. Again, this might take a few seconods, afterwards you should see the record you inserted in Client 1 appears in Client 2.

After first synchronization

8. Let's try a more complex sync. Add a new row in Client 2 and, in addition,  modify the first row in Client 2. Click "Save Client Data", and you should see the following message:

Two changes saved

9. Now, click "Synchronize" in Client 2 (you should see a message saying that 2 rows were uploaded) and in Client 1 (2 rows were downloaded). The windows should look like that:

Sync two changes

10. OK, let's conflict! Change the customer name in row 2 in Client 1, and click "Save Client Data". Do the same, with different customer name, in Client 2. You should see this:

Change two clients

11. Now, click "Synchronize" on Client 1. Remember: After synchronizing, the row in the Oracle is different than the one in Client 2.

12. Change the Sync Direction in Client 2 to "DownloadOnly". This is required since the conflict detection in this demo occurs in the client, and not the server.

13. Click "Synchronize" in Client 2. You should see the following message:

Conflict Message

You can choose whether to go on with the synchronization and overwrite the local values or abort it.

 

OK, that's all folks. I hope this demo did a good job in demonstrating how to use Sync Services with Oracle, using N-Tier architecture and conflicts detection. I didn't talk about the code at all because:

1. This post is already too long

2. The code is basically a merge of the samples posted in SyncGuru.

If you do want me to explain the code in later posts, please leave a comment.

 

If you find all this interesting, please download the demo and start synchronizing!

Published Monday, December 24, 2007 10:55 PM by MemiLavi

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Geek Lectures - Things geeks should know about » Blog Archive » Sync Services + N-Tier + Oracle + Conflict Detection said:

December 24, 2007 6:34 PM
 

Carlos Maltese said:

Hi

I can't  download the demo, the server returns a error :"Corrupted_Zip_file ". I can dowload this file from another link.

Thank's

January 8, 2008 10:11 AM
 

Memi Lavi said:

Mmmm... That's strange. I tried it now and ot worked flawlessly.

If you want, email me directly (memil@microsoft.com) and I'll send you the files.

January 9, 2008 2:25 AM
 

Carlos Maltese said:

Hi Memi

Sorry i just dowload the file with firefox.

thank's

January 9, 2008 5:46 AM
 

Jay Patel said:

Doesn't anyone want to sync w/ SQL Server (including Express) as a client?  It seems there are no 'Client Providers' for SQL Server other than for Compact Edition (CE).  For us CE is rather useless as we need a more robust solution for our mobile workforce (app is asp.net running on each workstation).

Anyone working on 'client' providers for SQL Server (not CE)?

mail -@- jaypatel -.- com

March 12, 2008 6:35 PM
 

MemiLavi said:

@Jay - I'm not aware of any work being done to enable other DB on the clients.

Why exectly isn't the CE good enough for you?

March 13, 2008 3:07 AM
 

David said:

I guess the reason I can't use SQL CE is because doesn't support store procs and my app rely a lot in store proc.

Is that a correct assumption?

Thanks,

David

May 21, 2008 2:30 PM
 

SQLCESYNC said:

Hi, I refer to the following:

Sync Services + N-Tier + Oracle + Conflict Detection

C:\Documents and Settings\kevin\My Documents\SyncServices\Project\Software Architecture and more___  Sync Services + N-Tier + Oracle + Conflict Detection.htm

by MemiLavi

The example used an Oracle Database (Oracle Database 10g Express Edition), how can I alter the example to use MS SQL Server 2008 / 2005 instead.

Regards

Kevin

June 24, 2008 7:07 AM
 

MemiLavi said:

Hi Kevin,

All you need to do is create the same database in SQL Server, change the connection string and make sure the SQL statements are MS SQL compliant.

The demo uses regular SQL statements, there is no special "magic" involved...

June 24, 2008 7:42 AM
 

LewInMadrid said:

I would like to do something similar but I have to access the Oracle database via a set of SOAP Web Services (using OC4J). Any ideas on how to progress?

September 16, 2008 6:05 AM
 

MemiLavi said:

I'm Sorry, but I have no experience with OC4J. I'm not sure sync services can deal with that.

September 17, 2008 3:40 AM
 

Jaz said:

Hi Memi,

I am also trying to develop something similar. I am facing problem creating the sdf files for the oracle database. Can you please help me regarding following things:

1) Creation of sdf file as per oracle database.

2) Explain the demo by step by step example.

Thanks,

Jaz

October 3, 2008 11:34 AM
 

Memi said:

Hi Jaz,

I'm not sure what exactly the problems are.

Could you be more specific? What step in the demo didn't you understand?

October 5, 2008 3:02 AM
 

Jaz said:

Hi Memi,

The problem is that, I have number of tables in Oracle database that i want to syncronize. I am not aware about method to generate the .sdf file for the Oracle tables.

Thanks,

Jaz

October 6, 2008 2:59 AM

Leave a Comment

(required) 
(optional)
(required) 
Submit

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker