locked
invalidCastException(Microsoft.Synchronization.Data.ClientSyncProvider) RRS feed

  • Question

  •  

    i am getting invalidCastException while running following code(line is marked in red where iam getting error).

     

    try

    {

    //

    // 1. Create instance of the sync components (client, agent, server)

    // This demo illustrates direct connection to server database. In this scenario,

    // sync components - client provider, sync agent and server provider - reside at

    // the client side. On the server, each table might need to be extended with sync

    // related columns to store metadata.

    DbServerSyncProvider serverSyncProvider = new DbServerSyncProvider();

    SyncAgent syncAgent = new SyncAgent();

    syncAgent.RemoteProvider = serverSyncProvider;

     

    SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();

    //

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

    //

    builder["Data Source"] = textServerMachine.Text;

    builder["integrated Security"] = false;

    builder["Initial Catalog"] = "My_DB";

    builder["User ID"] = "MyUser";

    SqlConnection serverConnection = new SqlConnection(builder.ConnectionString);

    serverSyncProvider.Connection = serverConnection;

    //

    // 3. Prepare client db connection and attach it to the sync provider

    //

    string connString = "Data Source=" + dbPathTextBox.Text;

    if (false == File.Exists(dbPathTextBox.Text))

    {

    SqlCeEngine clientEngine = new SqlCeEngine(connString);

    clientEngine.CreateDatabase();

    clientEngine.Dispose();

    }

    SqlCeClientSyncProvider clientSyncProvider = new SqlCeClientSyncProvider(connString);

    syncAgent.LocalProvider = clientSyncProvider;

     

    Also i  was doing sample from syncronization services for ADO.net books online ,

    i was getting same exception(How to: Download a Snapshot of Data to a Client).

     

    public class SampleSyncAgent : SyncAgent
        {
            public SampleSyncAgent()
            {           
                //Instantiate a client synchronization provider and specify it
                //as the local provider for this synchronization agent.
                this.LocalProvider = new SampleClientSyncProvider();

     

    PLEASE LET ME KNOW IF IT HAS TO DO WITH ANY VERSION OF MSF.

    • Moved by Max Wang_1983 Friday, April 22, 2011 4:59 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Tuesday, September 23, 2008 12:49 PM