locked
How do you specify the primary key when using SqlCeClientSyncProvider and DbServerSyncProvider RRS feed

  • Question

  • I get the following error when I try to sync a new table from the server to the client:

    Table '[Deliverable]' does not have a primary key. Add a primary key, or specify that a ROWGUIDCOL column should be used to uniquely identify rows in the table.

    My query on the server joins two tables and returns two fields that are uniqueidentifiers.  The SqlCeClientSyncProvider does not appear to know which one of the fields should be used as the primary key.  How do I tell it which of the returned columns should be used as the primary key?

    • Changed type dkeck Friday, October 2, 2009 2:21 PM
    • Moved by Max Wang_1983 Thursday, April 21, 2011 11:12 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Monday, September 28, 2009 7:46 PM

Answers

  • an easy way and a feasible way to deal with this is to hook to the CreatingSchema event on the client provider and check the Primarykey for the syncSchema for this table and specify a proper one there. please take a look at the SyncSchema session for details on how to set this.

    thanks
    Yunwen
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, October 5, 2009 1:30 AM
    Moderator

All replies

  • Hi Dkeck,

    the client provide requres PKs or rowguid column on the table as the exception indicates. a uniqueIdentifier type won't necessary to be a rowguid column.

    I assume you get this exception during the initial sync where creating the client side schema, right ? can you try to explictly set one of them as rowguid ? also please hookup with the creatingSchema event at the clientprovider to check the schema dataset of the table to ensure a rowguid is specified.

    thanks
    Yunwen
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, September 29, 2009 4:24 AM
    Moderator

  • Yunwen,

    This is happening during the initial sync when the client side schema is being created.  You indicate that I should explicity set one of the columns as a rowguid.  How would this be done?  The server appears to infer the schema from calls that are made to the server database.  ROWGUIDCOL does not appear to be something that I can add to the SQL join on the server to specify which column is a rowguid column.  Following is the SQL statement on the server that appears to be used by SqlCeClientSyncProvider to generate the schema.  If I remove either of the UniqueID columns from the query the local schema is created without any errors; however, leaving both UniqueID columns in causes the error.

      SELECT Deliverable.[UniqueID],
       IndividualPlan.[UniqueID] as IndividualPlanUniqueID,
       Deliverable.[Description],
          Deliverable.Rated as IsRated, Deliverable.Weight, Deliverable.SelfRatingRowID, Deliverable.LeaderRatingRowID as TeamLeaderRatingRowID,
          Deliverable.RatingReasonRowID as RatingReason, Deliverable.RatingComment as RatingComments, DeliverableHeader.Description as InitiativeName,
          Deliverable.PlannedStartDate as PlannedStart, Deliverable.PlannedEndDate as PlannedEnd, Deliverable.ActualStartDate as ActualStart,
          Deliverable.ActualEndDate as ActualEnd, Deliverable.PlannedHours,  Deliverable.LineTag as Tag,
         Project.UniqueID as ProjectUniqueID, ProjectWBS.UniqueID as ProjectWBSUniqueID, Deliverable.Unplanned as IsUnplanned
      FROM Deliverable LEFT OUTER JOIN
       CHANGETABLE(CHANGES Deliverable, @sync_last_received_anchor) CT ON CT.[UniqueID] = Deliverable.[UniqueID]
       left join IndividualPlan on IndividualPlan.RowID = Deliverable.IndividualPlanRowID
       left join Project on Project.RowID = Deliverable.ProjectRowID
       left join ProjectWBS on ProjectWBS.RowID = Deliverable.ProjectWBSRowID
       left join DeliverableHeader on DeliverableHeader.RowID = Deliverable.DeliverableHeaderRowID


    Wednesday, September 30, 2009 5:10 PM
  • an easy way and a feasible way to deal with this is to hook to the CreatingSchema event on the client provider and check the Primarykey for the syncSchema for this table and specify a proper one there. please take a look at the SyncSchema session for details on how to set this.

    thanks
    Yunwen
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, October 5, 2009 1:30 AM
    Moderator