locked
invalidCastException for localProvider. 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:55 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Tuesday, September 23, 2008 11:55 AM

All replies

  •  

    Most probably it is due to version mismatch of MSF. Can you please provide the versions of MSF and Sync Services For ADO.Net installed on your box?

     

    Tuesday, September 23, 2008 5:35 PM
    Moderator
  • I do have following things on my box.

    1>Microsoft sync framework runtime v1.0

    2>Microsoft sync framework sdk v1.0

    3>Microsoft sync framework services v1.0

    4>Microsoft sync services for ado.net v2.0

     

    Wednesday, September 24, 2008 4:54 AM
  • I hade to change the reference to Microsoft.Synchronization.Data.SqlServerCe from V 3.5.0.0 to V 2.0.0.0

    I did an upgrad for Sync services for ADO.net V 1 to V 2.

     

    Look at the pat of the dll file. Mine path is. C:\Program Files\Microsoft SDKs\Microsoft Sync Framework\v1.0\Runtime\ADO.NET\V2.0\x86\Microsoft.Synchronization.Data.SqlServerCe.dll

     

    /Christer

    Wednesday, September 24, 2008 10:02 AM