Synchronization -> Demo I

Hi!!

I followed the article of Rafik to make my first synchronization between SQL 2005 and SQLce. Everything works fine, BUT I've a little problem with primary and foreign keys...

I've 3 tables :

createtablePerson(

iduniqueidentifiernotnull,
firstNamenvarchar(25)null,
lastNamenvarchar(25)null,

constraint PK_PERSONprimarykeynonclustered(id))

createtableGroups(

iduniqueidentifiernotnull,
namenvarchar(25)null,
ownerIDuniqueidentifiernull,-- refers to a Person of table 'Person'
descriptionntextnull,

constraintPK_GROUPSprimarykeynonclustered(id))

createtableTakePart(

iduniqueidentifiernotnull,
personIDuniqueidentifiernull,-- refers to a Person of table 'Person'
groupIDuniqueidentifiernull,-- refers to a Group of table 'Groups'

constraintPK_TAKEPARTprimarykeynonclustered(id))

Situation :

One person take part to one group (= 1 record per table)

Problem :

When I want to delete the group with SQL Server Management, it returns an error. And this is completely normal, because this group is still in use in table 'TakePart'!! (error :The DELETE statement conflicted with the REFERENCE constraint "FK_TAKEPART_REFERENCE_GROUPS".)

BUT

When I delete this group from the client, it's no problem! The delete operation is made on the client database and when I synchronize it is not deleted on the server database.

So the client database and server database are no more synchronized! I think this is not very good

If somebody can help, thx

PS: and sorry for my poor english....

[5433 byte] By [PlaTyPuS8] at [2008-2-21]
# 1

Hi,

The reason you can make the delete on the client is that the FK constraints are not setup between the tables. The automatic creation of the schema on the client does not take care of everything. For example, indexes are not created on the client during schema creation. For this reason, the sync framework fires two schema creation events (CreatingSchema and SchemaCreated events) on the agent interface. These two events allows you to make changes to the schema since you will get access to the connection object and you could use it to setup PK-FK, Check Constraints, Indexes .. etc.

By the way, on the server, when a change is rejected like in your scenario, another event is fired ApplyChangeFailed event.

Thanks

RafikRobeal at 2007-9-12 > top of Msdn Tech,Visual Studio Orcas,Microsoft Synchronization Services for ADO.NET...
# 2

thx Rafik!

I think I will put the structure of database on my client!

PlaTyPuS8 at 2007-9-12 > top of Msdn Tech,Visual Studio Orcas,Microsoft Synchronization Services for ADO.NET...

Visual Studio Orcas

Site Classified