locked
DownloadOnly is not working RRS feed

  • Question

  • Hi,
    I am setting the commands of the server adapter as well as client adapter as below.

    SelectIncrementalInsertsCommand = SELECT [order_details_id],[order_id],[product],[quantity],[UpdatedBy] FROM [Order_details] WHERE CreateDateTime BETWEEN @sync_last_received_anchor + 1 and @sync_new_received_anchor  AND ISNULL(UpdatedBy,0) <> @sync_client_id_hash

    SelectIncrementalUpdatesCommand is clone of SelectIncrementalInsertsCommand

    InsertCommand = INSERT INTO Order_details([order_details_id],[order_id],[product],[quantity],[UpdatedBy]) VALUES(@order_details_id,@order_id,@product,@quantity,@sync_client_id_hash)

    UpdateCommand = UPDATE [Order_details] SET [order_id] = @order_id,[product] = @product,[quantity] = @quantity,[UpdatedBy]=@sync_client_id_hash WHERE [order_details_id] = @order_details_id

    I am adding the parameters also.

    The Upload and Bidirectional sync is working perfectly fine. But Download is not working. As a result of Sync, the SyncStatistics returns me the number of rows affected, but the data is not getting updated. Can you please tell me what am I missing here?

    • Moved by Hengzhe Li Friday, April 22, 2011 5:07 AM (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Friday, March 20, 2009 12:08 PM

Answers

  • Hi, the issue has been resolved. Changed the ApplyChanges method as below.

    public override SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession)

    {

    foreach (SyncTableMetadata tableMetadata in groupMetadata.TablesMetadata)

    {

    //if(tableMetadata.SyncDirection!=SyncDirection.Bidirectional)tableMetadata.SyncDirection = SyncDirection.UploadOnly;

    if (tableMetadata.SyncDirection == SyncDirection.DownloadOnly || tableMetadata.SyncDirection==SyncDirection.DownloadOnly)

    {

    //This SyncDirection DownloadOnly/Snapshot is from a Client point of view.

    //But our client is inturn a Server provider. Hence switch this to UploadOnly

    tableMetadata.SyncDirection = SyncDirection.UploadOnly;

    }

    //else if (tableMetadata.SyncDirection == SyncDirection.UploadOnly)

    //{

    // //This SyncDirection UploadOnly is from Client POV.

    // //But our client is inturn a Server provider. Hence switch this to DownloadOnly

    // tableMetadata.SyncDirection = SyncDirection.DownloadOnly;

    //}

    }

    SyncContext syncContext = _dbSyncProvider.ApplyChanges(groupMetadata, dataSet, syncSession);

    foreach (SyncTableMetadata table in groupMetadata.TablesMetadata)

    {

    SetTableReceivedAnchor(table.TableName, groupMetadata.NewAnchor);

    }

    return syncContext;

    }

    Monday, March 23, 2009 11:50 AM

All replies

  •  Adding code for reference.

    public
    void SetAdapters(XmlDocument xmlDoc, DbServerSyncProvider serverSyncProvider, SqlExpressClientSyncProvider clientSyncProvider,bool isServer)

    {

    SyncAdapter adapter = new SyncAdapter("orders");

    SqlCommand incInsertCommand = new SqlCommand("SELECT order_id, order_date FROM orders");

    SqlCommand incUpdateCommand = new SqlCommand("SELECT order_id, order_date FROM orders");

    SqlCommand insCommand = new SqlCommand("INSERT INTO Orders(order_id, order_date) VALUES(@order_id,@order_date)");

    SqlCommand updCommand = new SqlCommand("UPDATE Orders SET order_date=@order_date WHERE order_id=@order_id");

    adapter.SelectIncrementalInsertsCommand = incInsertCommand;

    adapter.SelectIncrementalUpdatesCommand = incUpdateCommand;

    insCommand.Parameters.Add("@order_id", SqlDbType.Int);

    insCommand.Parameters.Add("@order_date", SqlDbType.DateTime);

    adapter.InsertCommand = insCommand;

    updCommand.Parameters.Add("@order_id", SqlDbType.Int);

    updCommand.Parameters.Add("@order_date", SqlDbType.DateTime);

    adapter.UpdateCommand = updCommand;

    if(isServer)

    serverSyncProvider.SyncAdapters.Add(adapter);

    else

    clientSyncProvider.SyncAdapters.Add(adapter);

    }

    The call goes like this.

    SyncGroup group = new SyncGroup("GroupAll");

    SyncTable table = new SyncTable("orders");

    table.CreationOption = TableCreationOption.DropExistingOrCreateNewTable;

    table.SyncDirection = SyncDirection.UploadOnly;

    table.SyncGroup = group;

    syncAgent.Configuration.SyncTables.Add(table);

    //Create Adapters and define the commands for it

    SetAdapters(DataDocument,serverSyncProvider,clientSyncProvider,true);

    SetAdapters(DataDocument, serverSyncProvider, clientSyncProvider, false);

    .
    .
    .

    SyncStatistics syncStats = syncAgent.Synchronize();

    Friday, March 20, 2009 12:58 PM
  •  SyncDirection has been modified to DownloadOnly. It is shown as UploadOnly in the code sample by mistake.

    table.SyncDirection = SyncDirection.DownloadOnly;

    Friday, March 20, 2009 1:02 PM
  • Hi, the issue has been resolved. Changed the ApplyChanges method as below.

    public override SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession)

    {

    foreach (SyncTableMetadata tableMetadata in groupMetadata.TablesMetadata)

    {

    //if(tableMetadata.SyncDirection!=SyncDirection.Bidirectional)tableMetadata.SyncDirection = SyncDirection.UploadOnly;

    if (tableMetadata.SyncDirection == SyncDirection.DownloadOnly || tableMetadata.SyncDirection==SyncDirection.DownloadOnly)

    {

    //This SyncDirection DownloadOnly/Snapshot is from a Client point of view.

    //But our client is inturn a Server provider. Hence switch this to UploadOnly

    tableMetadata.SyncDirection = SyncDirection.UploadOnly;

    }

    //else if (tableMetadata.SyncDirection == SyncDirection.UploadOnly)

    //{

    // //This SyncDirection UploadOnly is from Client POV.

    // //But our client is inturn a Server provider. Hence switch this to DownloadOnly

    // tableMetadata.SyncDirection = SyncDirection.DownloadOnly;

    //}

    }

    SyncContext syncContext = _dbSyncProvider.ApplyChanges(groupMetadata, dataSet, syncSession);

    foreach (SyncTableMetadata table in groupMetadata.TablesMetadata)

    {

    SetTableReceivedAnchor(table.TableName, groupMetadata.NewAnchor);

    }

    return syncContext;

    }

    Monday, March 23, 2009 11:50 AM