locked
Please provide code to sync two SQL 2005 databases RRS feed

  • Question

  • Please provide code to sync two SQL 2005 databases

    Thanks,
    Diegolo
    • Moved by Hengzhe Li Thursday, April 21, 2011 7:44 AM (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Wednesday, December 9, 2009 4:02 AM

Answers

  • Yes, that's right.
    To be more precise, the difference to use a SQLCe Sync client and SQLServer Sync client is really minimal.
    I have summarized below the places where they differ:

    1. For provisioning.
    // Retrieve scope information from the server.          
    //
    DbSyncScopeDescription clientDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(scopeName, serverConn);

    if (peer.type == PeerType.SQL)
    {
        //For SQL client, do sync provisioning with the convenient Apply method directly.
        //
        SqlSyncScopeProvisioning clientProvisioning = new SqlSyncScopeProvisioning(clientDesc);
        clientProvisioning.Apply((SqlConnection) clientConn);
    }
    else if (peer.type == PeerType.SQLCe)
    {
        // For SQL Ce client, do sync provisioning with the convenient Apply method directly.
        //
        SqlCeSyncScopeProvisioning clientSqlCeProvisioning = new SqlCeSyncScopeProvisioning(clientDesc);
        clientSqlCeProvisioning.Apply((SqlCeConnection)clientConn);
    }

    2. For syncing with orchestrator, assume at this time, LocalProvider needs to be created.

    //when you create provider.
    //
    if (localConn is SqlCeConnection)
    {
        newSyncOrchestrator.LocalProvider = new SqlCeSyncProvider(scopeName, (SqlCeConnection)localConn);
    }
    else
    {
        newSyncOrchestrator.LocalProvider = new SqlSyncProvider(scopeName, (SqlConnection)localConn);
    }

    Wednesday, December 9, 2009 6:22 PM
    Answerer

All replies

  • it is in the MSDN,
    http://msdn.microsoft.com/en-us/library/dd918848%28SQL.105%29.aspx

    All you need to do is to change to use SqlSyncProvider in the code for both your server and nodes.

    Wednesday, December 9, 2009 4:22 AM
  • Yes, that's right.
    To be more precise, the difference to use a SQLCe Sync client and SQLServer Sync client is really minimal.
    I have summarized below the places where they differ:

    1. For provisioning.
    // Retrieve scope information from the server.          
    //
    DbSyncScopeDescription clientDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(scopeName, serverConn);

    if (peer.type == PeerType.SQL)
    {
        //For SQL client, do sync provisioning with the convenient Apply method directly.
        //
        SqlSyncScopeProvisioning clientProvisioning = new SqlSyncScopeProvisioning(clientDesc);
        clientProvisioning.Apply((SqlConnection) clientConn);
    }
    else if (peer.type == PeerType.SQLCe)
    {
        // For SQL Ce client, do sync provisioning with the convenient Apply method directly.
        //
        SqlCeSyncScopeProvisioning clientSqlCeProvisioning = new SqlCeSyncScopeProvisioning(clientDesc);
        clientSqlCeProvisioning.Apply((SqlCeConnection)clientConn);
    }

    2. For syncing with orchestrator, assume at this time, LocalProvider needs to be created.

    //when you create provider.
    //
    if (localConn is SqlCeConnection)
    {
        newSyncOrchestrator.LocalProvider = new SqlCeSyncProvider(scopeName, (SqlCeConnection)localConn);
    }
    else
    {
        newSyncOrchestrator.LocalProvider = new SqlSyncProvider(scopeName, (SqlConnection)localConn);
    }

    Wednesday, December 9, 2009 6:22 PM
    Answerer