none
Sync Services ADO.Net For Devices Primary Key Problem

    Question

  • Hello, I've developed a smart device application in Visual Studio 2008 that syncs back to a WCF Service and through to an SQL Server 2008 database.  I've got most of it working down to this poing.  When I try to sync this one table that has an identity column set up as the primary key. In this table I created another column that is uniqueidentifier type and set the default as NEWID().  I used sqlsyncadapterbuilder to generate the commands for the WCF service.  When I specified this table to the sqlsyncadapterbuilder I did not include the column that represented the identity primary key and included the uniqueidentifier column.  I then set the ROWGUIDCOLUMN property of the sqlsyncadapterbuilder to the uniqueidentifiercolumn.  The problem is when I sync to this table, the application throws an error that that table did not have a primary key specified and to either assign a primary key or specify the ROWGUIDCOLUMN.  Can anyone point me in the right direction on how to solve this problem?  Thanks for any and all help. 

    Tuesday, June 11, 2013 8:21 PM

Answers

  • just for debugging, can you inspect the adapter after you call ToSyncAdapter() if the ROWGUIDCOLUMN   was indeed set.

    • Marked as answer by CEDeveloper Wednesday, July 03, 2013 6:05 PM
    Thursday, June 13, 2013 12:45 AM
    Moderator

All replies

  • can you post the snippet where you specify the ROWGUIDCOLUMN  and the exact exception?
    Wednesday, June 12, 2013 1:06 AM
    Moderator
  • Hello JuneT.  The code I'm using is below and the exception is below that.  Thanks for your help.

     
                Dim builder = New SqlSyncAdapterBuilder(cnn)
    
                builder.TableName = ""
    
                builder.ChangeTrackingType = ChangeTrackingType.CoupledChangeTracking
                builder.SyncDirection = SyncDirection.Bidirectional
                builder.CreationTrackingColumn = "CREATE_DATETIME"
                builder.CreationOriginatorIdColumn = "CREATE_ID"
                builder.UpdateTrackingColumn = "UPDATE_DATETIME"
                builder.UpdateOriginatorIdColumn = "UPDATE_ID"
                   builder.TombstoneTableName = tableName & "_Tombstone"
                    builder.DeletionTrackingColumn = "DELETE_DATETIME"
                    builder.DeletionOriginatorIdColumn = "DELETE_ID"
    
    
                    builder.FilterClause = filterClause
    
                    builder.FilterParameters.Add(filterParamater)
    
    
                    builder.RowGuidColumn = primaryKey
    
    
                Dim adapter As SyncAdapter = builder.ToSyncAdapter()
    
                adapter.TableName = tableName
    
               

    Exception: Table '' 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.


    CEDeveloper

    Wednesday, June 12, 2013 2:12 AM
  • you're calling ToSyncAdapter() before you set the table name?
    Wednesday, June 12, 2013 2:46 AM
    Moderator
  • I would say that's just redundant coding on my part.  I set the table name in the adapter and then set it agin for the adapter after I called the ToSyncAdapter().


    CEDeveloper

    Wednesday, June 12, 2013 3:00 AM
  • so where is the part where you specify the columns to be included for the table?
    Wednesday, June 12, 2013 3:15 AM
    Moderator
  • Here it is.  Sorry about that.

            Dim rrmColumns(3) As String
    
            rrmColumns(0) = "GUID_REFNO"
            rrmColumns(1) = "CUSTOMERNO"
            rrmColumns(2) = "REFERENCENO"
            rrmColumns(3) = "COMMENTS"
    
            builder.DataColumns.AddRange(rrmColumns)
    
            primaryKey = "GUID_REFNO"
            


    CEDeveloper

    Wednesday, June 12, 2013 3:42 AM
  • Hello.  Does it look like I've specified anything wrong?  I've poured over the code I don't know how many times, but no luck figuring out what it is that's causing the problem.  Is it possibly something wrong from the database?  Thanks for the help.


    CEDeveloper

    Wednesday, June 12, 2013 3:38 PM
  • just for debugging, can you inspect the adapter after you call ToSyncAdapter() if the ROWGUIDCOLUMN   was indeed set.

    • Marked as answer by CEDeveloper Wednesday, July 03, 2013 6:05 PM
    Thursday, June 13, 2013 12:45 AM
    Moderator
  • I checked the syncadapterbuilder after setting the rowguidcolumn and it did set correctly.  I'm looking to see how to inspect the syncAdapter, but I'm not having any luck finding out how to check what was set for it.  Can you tell me how to check?  Thanks.

    CEDeveloper

    Thursday, June 13, 2013 6:34 PM
  • Thanks for your help JuneT.  I just went ahead and did a workaround on this to not let the user on the device insert a row for this table so I could get this sync going.  Thanks again.


    CEDeveloper

    Thursday, June 20, 2013 2:45 AM
  • Thanks for your help on this JuneT.  I had to revisit the problem and found that I had to add the the rowguid designation to the column within the client provider creating schema event.  Setting it there did the trick and everything seems to be working now.

    CEDeveloper

    Wednesday, July 03, 2013 6:05 PM