locked
why does the sync in this dll run 10 times slower if called from vb6 than c#? RRS feed

  • Question

  • I created c# class below to sync tables from sql server 2008 to compact 3.5 sp1.  I then created a c# class to force the sync to occur.  In the forcing code i put a stopwatch to see how long the .Synchronize() call takes.

     

    I wrote a tiny c# windows form program just to call the doit code.  Then I packaged the doit and sync classes into a COM assembly so I could call it from VB6.  The code is syncing 37 simple tables.  I even deleted all the data out of the tables.

     

    When I run the .net application, the initial data sync to an empty .sdf is 11 seconds.  A second bidirectional sync to the .sdf is 9 seconds.  With this application and the usual 778k of data is only marginally longer.

     

    When I run the VB6 application, the initial data sync to an empty .sdf is 71 seconds.  A second bidirectional sync to the .sdf is still over 1 minute.  With data this really stretches out.

     

    My goal is to use the sync foundation in a dll called from VB6, but I can't do it unless I can eliminate the unexplained longer running.  The complete source solution is available if requested.

     

    Thanks,

    Jeff Landry

     

     

     

    "doit code"

    public void doit()

    {

    staticTableSyncAgent staticTableAgent;

    //workingSyncAgent workingAgent;

    SyncStatistics syncStats;

    //AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", System.Environment.CurrentDirectory + @"\ClassLibrary.dll.config");

    SqlCeConnection forceConnection = connection;

    //force sdf to sync down the configuration files including tellinfo

    staticTableAgent = new staticTableSyncAgent();

    Stopwatch watch = new Stopwatch();

    watch.Reset();

    watch.Start();

    syncStats = staticTableAgent.Synchronize();

    watch.Stop();

    }

     

     

    Sync framework classes

    {

    public partial class staticTableSyncClientSyncProvider : Microsoft.Synchronization.Data.SqlServerCe.SqlCeClientSyncProvider

    {

    public staticTableSyncClientSyncProvider()

    {

    this.ConnectionString = @"Data Source=" + System.Environment.CurrentDirectory + @"\testSync.sdf";

    }

    }

    public partial class staticTableSyncAgent : Microsoft.Synchronization.SyncAgent

    {

    public staticTableSyncAgent()

    {

    this.InitializeSyncProviders();

    newSyncTable("BAL_RECPT");

    //newSyncTable("bank");

    newSyncTable("Batch_info");

    newSyncTable("Batchlist");

    //newSyncTable("branch");

    //newSyncTable("branch_locations");

    newSyncTable("Bsa");

    newSyncTable("Button_captions");

    newSyncTable("Check_wizard");

    newSyncTable("Comparisons");

    newSyncTable("Cond_req");

    newSyncTable("Ctr");

    newSyncTable("Dataseq");

    newSyncTable("Fee");

    newSyncTable("Field_info");

    //newSyncTable("financial_institution");

    newSyncTable("GENERAL_OPTIONS");

    newSyncTable("Group_info");

    newSyncTable("Grouplist");

    newSyncTable("Inq_list");

    newSyncTable("Laser_writer");

    newSyncTable("Laser_writer_lookup");

    //newSyncTable("Long_recpt");

    newSyncTable("Menu_header");

    newSyncTable("Misc_info");

    newSyncTable("Mkt_msg");

    newSyncTable("Mod_info");

    newSyncTable("Mod_list");

    newSyncTable("Msg_header");

    newSyncTable("Passbook");

    newSyncTable("Passbook_info");

    newSyncTable("Payout_options");

    newSyncTable("Popup_menu_info");

    newSyncTable("Popup_menus");

    newSyncTable("Pre_fill");

    newSyncTable("Preprinted_docs");

    newSyncTable("Print_info");

    newSyncTable("Reference_books");

    newSyncTable("Reference_chapters");

    newSyncTable("Trans_info");

    newSyncTable("Translist");

    newSyncTable("Usr_def");

    }

    private void InitializeSyncProviders()

    {

    // Create SyncProviders.

    this.RemoteProvider = new staticTableSyncServerSyncProvider();

    this.LocalProvider = new staticTableSyncClientSyncProvider();

    }

    void newSyncTable(string tableName)

    {

    SyncTable aSyncTable;

    aSyncTable = new SyncTable(tableName);

    aSyncTable.CreationOption = TableCreationOption.UploadExistingOrCreateNewTable;

    aSyncTable.SyncDirection = SyncDirection.Bidirectional;

    this.Configuration.SyncTables.Add(aSyncTable);

    }

    }

    public partial class staticTableSyncServerSyncProvider : Microsoft.Synchronization.Data.Server.DbServerSyncProvider

    {

    public staticTableSyncServerSyncProvider()

    {

    this.Connection = new SqlConnection("server=joule;uid=testSync;pwd=testSync;Database=testSyncNoData");

    newSyncAdapter("BAL_RECPT");

    //newSyncAdapter("bank");

    newSyncAdapter("Batch_info");

    newSyncAdapter("Batchlist");

    //newSyncAdapter("branch");

    //newSyncAdapter("branch_locations");

    newSyncAdapter("Bsa");

    newSyncAdapter("Button_captions");

    newSyncAdapter("Check_wizard");

    newSyncAdapter("Comparisons");

    newSyncAdapter("Cond_req");

    newSyncAdapter("Ctr");

    newSyncAdapter("Dataseq");

    newSyncAdapter("Fee");

    newSyncAdapter("Field_info");

    //newSyncAdapter("financial_institution");

    newSyncAdapter("GENERAL_OPTIONS");

    newSyncAdapter("Group_info");

    newSyncAdapter("Grouplist");

    newSyncAdapter("Inq_list");

    newSyncAdapter("Laser_writer");

    newSyncAdapter("Laser_writer_lookup");

    //newSyncAdapter("Long_recpt");

    newSyncAdapter("Menu_header");

    newSyncAdapter("Misc_info");

    newSyncAdapter("Mkt_msg");

    newSyncAdapter("Mod_info");

    newSyncAdapter("Mod_list");

    newSyncAdapter("Msg_header");

    newSyncAdapter("Passbook");

    newSyncAdapter("Passbook_info");

    newSyncAdapter("Payout_options");

    newSyncAdapter("Popup_menu_info");

    newSyncAdapter("Popup_menus");

    newSyncAdapter("Pre_fill");

    newSyncAdapter("Preprinted_docs");

    newSyncAdapter("Print_info");

    newSyncAdapter("Reference_books");

    newSyncAdapter("Reference_chapters");

    newSyncAdapter("Trans_info");

    newSyncAdapter("Translist");

    newSyncAdapter("Usr_def");

    this.InitializeNewAnchorCommand();

    }

    void newSyncAdapter(string tableName)

    {

    SyncAdapter aSyncAdapter;

    SqlSyncAdapterBuilder builder;

    builder = new SqlSyncAdapterBuilder();

    builder.Connection = (SqlConnection)this.Connection;

    builder.ChangeTrackingType = ChangeTrackingType.SqlServerChangeTracking;

    builder.SyncDirection = Microsoft.Synchronization.Data.SyncDirection.Bidirectional;

    //as a test, don't set the datacolums and see if it just uses all by itself

    builder.TableName = tableName;

    aSyncAdapter = builder.ToSyncAdapter();

    SyncAdapters.Add(aSyncAdapter);

    }

    private void InitializeNewAnchorCommand()

    {

    // selectNewAnchorCmd command.

    this.SelectNewAnchorCommand = new System.Data.SqlClient.SqlCommand();

    this.SelectNewAnchorCommand.CommandText = "Select @sync_new_received_anchor = CHANGE_TRACKING_CURRENT_VERSION()";

    this.SelectNewAnchorCommand.CommandType = System.Data.CommandType.Text;

    System.Data.SqlClient.SqlParameter selectnewanchorcommand_sync_new_received_anchorParameter = new System.Data.SqlClient.SqlParameter("@sync_new_received_anchor", System.Data.SqlDbType.BigInt);

    selectnewanchorcommand_sync_new_received_anchorParameter.Direction = System.Data.ParameterDirection.Output;

    this.SelectNewAnchorCommand.Parameters.Add(selectnewanchorcommand_sync_new_received_anchorParameter);

    }

    }

    Thursday, November 20, 2008 9:24 PM