views:

467

answers:

2

Hi,

Hopefully someone can help me. I have a Visual Studio 2008 WinForms application to which I have added a Local Data Cache. The local data cache is using a SDF file via SqlServerCE and is caching a SQL Server 2008 dbase with change tracking enabled.

This is working and I can do bidirectional syncs and the like.

The problem I am having is with inserting data in to the local tables that have been created by the VS wizards. When I try insert data either programmatically or even through the VS interface (show data) I get a error stating “A duplicate value cannot be inserted into a unique index” due to a primary key constraint.

The tables have a auto inc int primary key and it seems like the seed has been reset back to one. This doesn’t happen to all the tables though, only a few.

Any ideas how I can fix this?

Regards, Adam

A: 

hi Adam,

  • can you post the Server DDL Statement for the relevant table?
  • How are you creating the primary keys on the client? The error Message says you are trying to insert the same PrimaryKey again in the table.
  • Maybe also consider sqlce does not support server generated keys
Martin Dürrmeier
A: 

I had same issue, and replaced Int/auto-incremental values with GUIDs. works good for me.