example SqlExpressClientSyncProvider RRS feed

  • Question

  • Hello Experts,


    have someone any experience with this example?

    I tried out this example and anything going well til I try to synchronize.



    Code Snippet

    DbServerSyncProvider serverSyncProvider = new DbServerSyncProvider();

    SqlExpressClientSyncProvider clientSyncProvider = new SqlExpressClientSyncProvider();

    SyncAgent syncAgent = new SyncAgent();

    syncAgent.RemoteProvider = serverSyncProvider;

    syncAgent.LocalProvider = clientSyncProvider;



    last row fails with error:


    System.InvalidCastException: Microsoft.Synchronization.Data.ClientSyncProvider

       at Microsoft.Synchronization.SyncAgent.set_LocalProvider(SyncProvider value)

       at SQLExpressProviderSample.SyncEngine.Synchronize() in C:\Documents and Settings\Sample\SyncEngine.cs:line 73

       at SQLExpressProviderSample.SyncForm.buttonSynchronize_Click(Object sender, EventArgs e) in C:\Documents and Settings\Sample\SyncForm.cs:line 110


    Has someone any idea?


    To add and delete random items at client and server going well.


    Best regards,


    • Moved by Max Wang_1983 Friday, April 22, 2011 5:56 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Wednesday, September 3, 2008 2:39 PM


All replies


    Check the following to assure that they were working properly and made changes so you might check the following:


    1. Create SyncTable for each table:

                SyncTable tableOrders = new SyncTable("orders");
                tableOrders.CreationOption = TableCreationOption.DropExistingOrCreateNewTable;
                tableOrders.SyncDirection = SyncDirection.Bidirectional;


    2. Create SyncGroup:


    SyncGroup orderGroup = new SyncGroup("AllChanges");

    3. Add each SyncTable to the SyncGroup


    tableOrders.SyncGroup = orderGroup;


    4. add each table to the SyncAgent




    5. make sure each table name is in anchor table


    6. make sure all tables have the fields with proper triggers: 

    create_timestamp bigint NULL DEFAULT (@@dbts+(1)),

    update_timestamp timestamp NOT NULL,

    update_originator_id int NULL DEFAULT ((0))

    Wednesday, September 3, 2008 5:01 PM
  • ok. thanks a lot. in about 12 hours I can check your setting.
    Wednesday, September 3, 2008 5:59 PM
  • Hello,


    I checked your settings and there all looks fine.


    The dugger don't come tot this line. I've get an exception at the follow line

    Code Snippet


    syncAgent.LocalProvider = clientSyncProvider;



    dubugger didn't come to the second step called

    // 2. Prepare server db connection and attach it to the sync agent


    Thursday, September 4, 2008 6:55 AM
  • 1. I resolve my problem by writing my own class


    Code Snippet

    public class mySyncAgent : SyncAgent


    new public SqlExpressClientSyncProvider LocalProvider { get; set; }




    Code Snippet

    DbServerSyncProvider serverSyncProvider = new DbServerSyncProvider();

    SqlExpressClientSyncProvider clientSyncProvider = new SqlExpressClientSyncProvider();

    //SyncAgent syncAgent = new SyncAgent();

    mySyncAgent syncAgent = new mySyncAgent();

    syncAgent.RemoteProvider = serverSyncProvider;

    syncAgent.LocalProvider = clientSyncProvider;




    right now my code going well and I can take the next step Smile


    2. Right now I've got a new problem:

    file SyncEngine.cs fails in the method "AddClientSyncAdapters"at the line

    Code Snippet



    ErrorTongue Tiedystem.ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.


    I let all default code doing by example.


    Could someone help me, please?




    Thursday, September 4, 2008 9:11 AM


    The original problematic code that you posted should work fine. The error tells me that maybe your SyncServices installation is may be corrupt or your reference assemblies in your sample app might not be correct. Can you reply back with what version of SyncServices for ADO.Net you have installed and which version of the Microsoft.Synchronization.dll and Microsoft.Synchronization.Data.Server.dll you are referencing.


    Thursday, September 4, 2008 8:24 PM
  • Hello Mahesh,


    I istalled

    - Microsoft Sync Services for ADO.Net v2.0(x86)

    - Microsoft Syncchronization Services for ADO.Net (Devices)


    I use:

    Microsoft.Synchronization.dll:                    RuntimeVersion :v2.0.50727;             version1.0.0.0

    Microsoft.Synchronization.Data.Server.dll:  RuntimeVersion;                               version


    Some idea?



    Monday, September 8, 2008 1:09 PM
  • No wonder. The devices one is only for devices (and its a CTP) and doesnt apply to the desktop. Please download and install the Sync services for ADO.NET from this link http://www.microsoft.com/downloads/details.aspx?FamilyId=C88BA2D1-CEF3-4149-B301-9B056E7FB1E6&displaylang=en



    Its desktop specific.

    Monday, September 8, 2008 5:45 PM
  • ok, thanks a lot !
    Tuesday, September 9, 2008 7:12 AM