locked
Using mdf file on client side RRS feed

  • Question

  • Can we use mdf file on ClientSide? when i debug the application it is giving initial catelog cannot be used. If its possible to use mdf then please let me know with the help of few articles.
    Thursday, April 15, 2010 6:52 AM

Answers

All replies

  • have you checked your connection string? you should be able to attach an MDF and use it on SyncFx.

    Thursday, April 15, 2010 9:10 AM
  • Hi June,

        I am posting my code and app.config, please check and let me know where i am wrong.

    using

     

    System;

    using

     

    System.Collections.Generic;

    using

     

    System.Linq;

    using

     

    System.Text;

    using

     

    Microsoft.Synchronization.Data.SqlServerCe;

    using

     

    System.Configuration;

    using

     

    Microsoft.Synchronization.Data.Server;

    using

     

    System.Data.SqlClient;

    using

     

    Microsoft.Synchronization.Data;

    using

     

    Microsoft.Synchronization;

    namespace

     

    ConsoleApplication6

    {

     

    classProgram

    {

     

    staticvoid Main(string[] args)

    {

     

    samplestat stat =newsamplestat();

     

    samplesyncagent agent =newsamplesyncagent();

     

    SyncStatistics syncstatic = agent.Synchronize();

    stat.displaystat(syncstatic,

    "initial");

    syncstatic = agent.Synchronize();

    stat.displaystat(syncstatic,

    "sunsequent");

     

    Console.ReadLine();

     

    }

    }

     

    publicclasssampleClientSyncprovider :SqlCeClientSyncProvider

    {

     

    public sampleClientSyncprovider()

    {

     

    string conn =ConfigurationManager.ConnectionStrings["anupConnectionString1"].ConnectionString;

     

    this.ConnectionString = conn;

    }

    }

     

    publicclasssampleserversyncprovider :DbServerSyncProvider

    {

     

    public sampleserversyncprovider()

    {

     

    string conn =ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;

     

    SqlConnection con =newSqlConnection(conn);

     

    this.Connection = con;

     

    SyncAdapter adapter =newSyncAdapter("Customers");

     

    SqlCommand cmd =newSqlCommand();

    cmd.CommandText =

    "SELECT * FROM Customers";

    cmd.Connection = con;

    adapter.SelectIncrementalInsertsCommand = cmd;

     

    this.SyncAdapters.Add(adapter);

    }

    }

     

    publicclasssamplestat

    {

     

    publicvoid displaystat(SyncStatistics stat, string synctype)

    {

     

    Console.WriteLine(string.Empty);

     

    if (synctype =="initial")

    {

     

    Console.WriteLine("initailiaze sync adapter");

    }

     

    else

    {

     

    if (synctype =="sunsequent")

    {

     

    Console.WriteLine("subsequent sync");

     

    Console.WriteLine("start time" + stat.SyncStartTime);

     

    Console.WriteLine("total changes downloaded" + stat.TotalChangesDownloaded);

     

    Console.WriteLine("upload changes applied" + stat.UploadChangesApplied);

     

    Console.WriteLine(stat.DownloadChangesApplied);

     

    Console.WriteLine("end time" + stat.SyncCompleteTime);

     

    Console.WriteLine(string.Empty);

    }

    }

    }

    }

     

    publicclasssamplesyncagent :SyncAgent

    {

     

    public samplesyncagent()

    {

     

    this.LocalProvider =newsampleClientSyncprovider();

     

    this.RemoteProvider =newsampleserversyncprovider();

     

    SyncGroup group =newSyncGroup("Customers");

     

    SyncTable table =newSyncTable("Customers");

    table.CreationOption =

    TableCreationOption.DropExistingOrCreateNewTable;

    table.SyncDirection =

    SyncDirection.DownloadOnly ;

    table.SyncGroup = group;

     

    this.Configuration.SyncTables.Add(table);

    }

    }

    }

     

    <?

     

    xmlversion="1.0"encoding="utf-8" ?>

    <

     

    configuration>

    <

     

    connectionStrings>

    <

     

    addname="NorthwindConnectionString"connectionString="Data Source=BLRWKS0066\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True"

     

     

    providerName="System.Data.SqlClient" />

    <

     

    addname="ClientNorthwindConnectionString"connectionString="Data Source=|DataDirectory|\Northwind.sdf;Max Database Size=2047"

     

     

    providerName="Microsoft.SqlServerCe.Client.3.5" />

    <

     

    addname="anupConnectionString1"connectionString="Data Source=BLRWKS0066\SQLEXPRESS;Initial Catalog=anup;Integrated Security=True"

     

     

    providerName="System.Data.SqlClient" />

    </

     

    connectionStrings>

    </

     

    configuration>

    error is Unknown connection option in connection string: initial catalog.

    Thursday, April 15, 2010 9:29 AM
  • your sampleClientSyncProvider is deriving from SqlCeClientSyncProvider and you're passing it a SQLClient connection instead of an SqlServerCe.Client connection.

    change your anupConnectionString to connect to the SDF instead if that's what you intend to sync.

    or are you trying to use SQL Express for the client? If you are, you can't use the SqlCeClientSyncProvider to sync an SQL Express database.

    You can either download the sample SQLExpressClientSyncProvider or you move to Sync FX v2 and use the SQLSyncProvider collaboration provider instead

    Thursday, April 15, 2010 10:04 AM
  • can you please show me with an example? i am not able to understand. Please help
    Friday, April 16, 2010 12:01 PM
  • can you specify which do you want to sync? SQL Express/Server and SQLExpress/Server or SQL Compact to SQLExpress/Server?

    in your code above, anupConnectionString is pointing to a SQLExpress instance but the client provider where you're using it is an SQL CE provider with a different connection type.

    Friday, April 16, 2010 4:10 PM
  • I want to use sqlExpress/Server. sorry for the late reply.
    Monday, April 19, 2010 12:24 PM
  • if its SQLExpress to SQL Server, the designer generated code is for SQL Compact to SQL Server, so you have to replace the SQLCEClientSyncProvider. Unfortunately, there is no out-of-the-box SQL Express client sync provider, only a sample provider which you can find from here: http://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=sync&ReleaseId=1200

    if you want to use the V2 collaboration providers instead, you can find  sample here: http://code.msdn.microsoft.com/sync/Release/ProjectReleases.aspx?ReleaseId=3422 , justreplace the SqlCeSyncProvider with SQLSyncProvider.

     

    • Marked as answer by JuneT Thursday, July 8, 2010 1:39 PM
    Monday, April 19, 2010 11:22 PM