locked
wrong table order at sync (server side) RRS feed

  • Question

  • Hi guys,

    I have a problem synchronizing a set of tables:

       syncAgent.Configuration.SyncTables.Add("Vehicle", Microsoft.Synchronization.Data.TableCreationOption.UseExistingTableOrFail, Microsoft.Synchronization.Data.SyncDirection.Bidirectional, new SyncGroup("Vehicle"));
                    syncAgent.Configuration.SyncTables.Add("VehicleAxles", Microsoft.Synchronization.Data.TableCreationOption.UseExistingTableOrFail, Microsoft.Synchronization.Data.SyncDirection.Bidirectional, new SyncGroup("Vehicle"));
                    syncAgent.Configuration.SyncTables.Add("VehicleTyreInfo", Microsoft.Synchronization.Data.TableCreationOption.UseExistingTableOrFail, Microsoft.Synchronization.Data.SyncDirection.Bidirectional, new SyncGroup("Vehicle"));
                    syncAgent.Configuration.SyncTables.Add("VehicleTyres", Microsoft.Synchronization.Data.TableCreationOption.UseExistingTableOrFail, Microsoft.Synchronization.Data.SyncDirection.Bidirectional, new SyncGroup("Vehicle"));
                    syncAgent.Configuration.SyncTables.Add("VehicleMileage", Microsoft.Synchronization.Data.TableCreationOption.UseExistingTableOrFail, Microsoft.Synchronization.Data.SyncDirection.Bidirectional, new SyncGroup("Vehicle"));

    I checked with SQL Profiler and the problem is that the rows in VehicleTyres are inserted before the rows in VehicleTyreInfo resulting in a FK error. But I don't get any error at the client side, just the number of rows that were correctly inserted. Is it possible to control the order of the tables in the sync process? Is the table order decided automatically by the sync framework?

    Below are some Sql statements from Profiler to get an idea about the table structure:

     

    declare @p9 int
    set @p9=0
    exec sp_executesql N'INSERT INTO dbo.VehicleTyres ([VehicleID], [AxlePosition], [PositionOnAxle], [VehicleTyreInfoID], [LastEditDate], [CreationDate]) VALUES (@VehicleID, @AxlePosition, @PositionOnAxle, @VehicleTyreInfoID, @LastEditDate, @CreationDate) SET @sync_row_count = @@rowcount',N'@VehicleID uniqueidentifier,@AxlePosition int,@PositionOnAxle int,@VehicleTyreInfoID uniqueidentifier,@LastEditDate datetime,@CreationDate datetime,@sync_row_count int output',@VehicleID='DB420DD8-751B-46D0-A9A4-6830E6F6B465',@AxlePosition=0,@PositionOnAxle=4,@VehicleTyreInfoID='2D30A7FE-6697-41C6-985E-7D8E1065448F',@LastEditDate=NULL,@CreationDate=NULL,@sync_row_count=@p9 output
    select @p9

     

    declare @p24 int
    set @p24=1
    exec sp_executesql N'INSERT INTO dbo.VehicleTyreInfo ([VehicleTyreInfoID], [Bac], [TyreBrandID], [TyreTypeID], [Width], [Height], [WheelSize], [SpeedIndex1], [SpeedIndex2], [LoadIndex1], [LoadIndex2], [Retreaded], [Serialnumber], [Reprofiled], [AdvisedPressure], [Nitrogen], [ScrapTyre], [Casing], [TreadDepth], [LastEditDate], [CreationDate]) VALUES (@VehicleTyreInfoID, @Bac, @TyreBrandID, @TyreTypeID, @Width, @Height, @WheelSize, @SpeedIndex1, @SpeedIndex2, @LoadIndex1, @LoadIndex2, @Retreaded, @Serialnumber, @Reprofiled, @AdvisedPressure, @Nitrogen, @ScrapTyre, @Casing, @TreadDepth, @LastEditDate, @CreationDate) SET @sync_row_count = @@rowcount',N'@VehicleTyreInfoID uniqueidentifier,@Bac varchar(23),@TyreBrandID int,@TyreTypeID int,@Width decimal(4,1),@Height decimal(3,1),@WheelSize decimal(3,1),@SpeedIndex1 varchar(1),@SpeedIndex2 varchar(8000),@LoadIndex1 int,@LoadIndex2 int,@Retreaded bit,@Serialnumber varchar(7),@Reprofiled bit,@AdvisedPressure decimal(29,0),@Nitrogen bit,@ScrapTyre bit,@Casing bit,@TreadDepth decimal(1,0),@LastEditDate datetime,@CreationDate datetime,@sync_row_count int output',@VehicleTyreInfoID='E92741BB-4862-4E9C-8436-A12781464306',@Bac='B.AE.315.80.225.K.08.00',@TyreBrandID=21,@TyreTypeID=1951,@Width=315.0,@Height=80.0,@WheelSize=22.5,@SpeedIndex1='K',@SpeedIndex2='',@LoadIndex1=156,@LoadIndex2=0,@Retreaded=NULL,@Serialnumber='Serial1',@Reprofiled=NULL,@AdvisedPressure=NULL,@Nitrogen=NULL,@ScrapTyre=NULL,@Casing=NULL,@TreadDepth=0,@LastEditDate=NULL,@CreationDate=NULL,@sync_row_count=@p24 output
    select @p24

     

    Monday, November 1, 2010 10:12 AM

Answers

  • I already found a solution. Seems that the order of the tables is the one defined in InitializeSyncAdapters

       [System.Diagnostics.DebuggerNonUserCodeAttribute()]
            private void InitializeSyncAdapters() {
                // Create SyncAdapters.
                this._tyreSyncAdapter = new TyreSyncAdapter();
                this.SyncAdapters.Add(this._tyreSyncAdapter);
                this._tyreTypeSyncAdapter = new TyreTypeSyncAdapter();
                this.SyncAdapters.Add(this._tyreTypeSyncAdapter);
                this._tyreBrandSyncAdapter = new TyreBrandSyncAdapter();
                this.SyncAdapters.Add(this._tyreBrandSyncAdapter);
                this._vehicleSyncAdapter = new VehicleSyncAdapter();
                this.SyncAdapters.Add(this._vehicleSyncAdapter);
                this._vehicleAxlesSyncAdapter = new VehicleAxlesSyncAdapter();
                this.SyncAdapters.Add(this._vehicleAxlesSyncAdapter);
                this._vehicleMileageSyncAdapter = new VehicleMileageSyncAdapter();
                this.SyncAdapters.Add(this._vehicleMileageSyncAdapter);
                this._vehicleTyreInfoSyncAdapter = new VehicleTyreInfoSyncAdapter();
                this.SyncAdapters.Add(this._vehicleTyreInfoSyncAdapter);
                this._vehicleTyresSyncAdapter = new VehicleTyresSyncAdapter();
                this.SyncAdapters.Add(this._vehicleTyresSyncAdapter);
                this._aspnet_MembershipSyncAdapter = new aspnet_MembershipSyncAdapter();
                this.SyncAdapters.Add(this._aspnet_MembershipSyncAdapter);
                this._aspnet_UsersSyncAdapter = new aspnet_UsersSyncAdapter();
                this.SyncAdapters.Add(this._aspnet_UsersSyncAdapter);
                this._companySyncAdapter = new CompanySyncAdapter();
                this.SyncAdapters.Add(this._companySyncAdapter);
                this._companyAddressSyncAdapter = new CompanyAddressSyncAdapter();
                this.SyncAdapters.Add(this._companyAddressSyncAdapter);
                this._companyFleetCheckSyncAdapter = new CompanyFleetCheckSyncAdapter();
                this.SyncAdapters.Add(this._companyFleetCheckSyncAdapter);
                this._addressSyncAdapter = new AddressSyncAdapter();
                this.SyncAdapters.Add(this._addressSyncAdapter);
                this._companyGroupSyncAdapter = new CompanyGroupSyncAdapter();
                this.SyncAdapters.Add(this._companyGroupSyncAdapter);
                this._controlesSyncAdapter = new ControlesSyncAdapter();
                this.SyncAdapters.Add(this._controlesSyncAdapter);
                this._measurementsSyncAdapter = new MeasurementsSyncAdapter();
                this.SyncAdapters.Add(this._measurementsSyncAdapter);
                this._usersFleetcheckPreferencesSyncAdapter = new UsersFleetcheckPreferencesSyncAdapter();
                this.SyncAdapters.Add(this._usersFleetcheckPreferencesSyncAdapter);
            }

    Monday, November 1, 2010 1:33 PM