none
Not understanding SP's RRS feed

  • Question

  • I'm new to the Sync Framework. I'm using version 2.1. Currently I'm syncing 2 Compact databases. It has the following:

    TABLE:  Test

    Column: Text - PK, nvarchar(100), not null

    I have the following code being used.

          Microsoft.Synchronization.SyncOrchestrator SyncOrc = new Microsoft.Synchronization.SyncOrchestrator();
    
          SqlCeConnection ServerConn = new SqlCeConnection(@"Data Source=C:\Users\<Username>\Documents\Visual Studio 2010\Projects\SyncFrameTest\SyncFrameTest-SQL\Bin\Debug\ServerDatabase.sdf");
          SqlCeConnection ClientConn = new SqlCeConnection(@"Data Source=C:\Users\<Username>\Documents\Visual Studio 2010\Projects\SyncFrameTest\SyncFrameTest-SQL\Bin\Debug\ClientDatabase.sdf");
    
          Microsoft.Synchronization.Data.RelationalSyncProvider CEServerDB = new Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncProvider("Server", ServerConn);
          Microsoft.Synchronization.Data.RelationalSyncProvider CEClientDB = new Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncProvider("Client", ClientConn);
    
    SyncOrc.LocalProvider = CEClientDB;
          SyncOrc.RemoteProvider = CEServerDB;
          SyncOrc.Direction = Microsoft.Synchronization.SyncDirectionOrder.DownloadAndUpload;
    
    Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncScopeProvisioning Provision = new Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncScopeProvisioning(ClientConn);
    
    Microsoft.Synchronization.Data.DbSyncScopeDescription ScopeDesc = Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncDescriptionBuilder.GetDescriptionForScope(CEClientDB.ScopeName, ClientConn);
    
            Provision.SetCreateTableDefault(Microsoft.Synchronization.Data.DbSyncCreationOption.CreateOrUseExisting);
    
            Provision.PopulateFromScopeDescription(ScopeDesc);
    
            Provision.Apply();
    
    SyncOrc.Synchronize();
    

    When I run this I keep getting something about the database not being provisioned for sync.

    The current operation could not be completed because the database is not provisioned for sync or you not have permissions to the sync configuration tables.

    I looked up more information on this error and it seems that I'm missing a ScopeInfo table and something else. I looked on MSDN for more information but I'm not exactly understanding everything it's saying. I'm not much of a database dev so I'm a little stuck. Can someone make it a little more simple for me? I'm not sure what I'm suppose to put into the ScopeInfo table. If someone can explain how this connects to the table I have (Test) maybe I can understand it a little better. I also don't understand what triggers do.

    Or, is there a way to get the Sync Framework to generate the code for me?

    Sorry for being a complete noob. Thanks in advance!


    Owner, Quilnet Solutions
    Sunday, January 23, 2011 2:54 AM

Answers

  • you can simply copy the completed code at the end of each walkthrough. they are not made for dba's either.

    you have the option to construct the table structure yourself. if its already created, you can retrieve the structure as well. the walkthroughs has a sample of it as well on how to do both.

    the provisioning is automated for you, you just have to tell it which tables you want to synchronize. and provisioning has to be on both sides being synchronized.

    • Marked as answer by Quilnux Tuesday, January 25, 2011 12:42 AM
    Sunday, January 23, 2011 1:40 PM
    Moderator
  • I managed to get it. As usually, I was doing it wrong.

    This is the correct code for Sync Framework 2.1.

          Microsoft.Synchronization.SyncOrchestrator SyncOrc = new Microsoft.Synchronization.SyncOrchestrator();
    
          SqlCeConnection ServerConn = new SqlCeConnection(@"Data Source=C:\Users\<username>\Documents\Visual Studio 2010\Projects\SyncFrameTest\SyncFrameTest-SQL\Bin\Debug\ServerDatabase.sdf");
          SqlCeConnection ClientConn = new SqlCeConnection(@"Data Source=C:\Users\<username>\Documents\Visual Studio 2010\Projects\SyncFrameTest\SyncFrameTest-SQL\Bin\Debug\ClientDatabase.sdf");
    
          try
          {
            if (System.IO.File.Exists("ClientDatabase.sdf"))
            {
              System.IO.File.Delete("ClientDatabase.sdf");
            }
          }
          catch (Exception ex)
          { }
    
          System.Data.SqlServerCe.SqlCeEngine CEEngine = new SqlCeEngine(ClientConn.ConnectionString);
          CEEngine.CreateDatabase();
    
          CEEngine.Dispose();
    
          Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncProvider CEServerDB = new Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncProvider("TestScope", ServerConn);
          Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncProvider CEClientDB = new Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncProvider("TestScope", ClientConn);
    
          SyncOrc.LocalProvider = CEClientDB;
          SyncOrc.RemoteProvider = CEServerDB;
          SyncOrc.Direction = Microsoft.Synchronization.SyncDirectionOrder.DownloadAndUpload;
    
          try
          {
    
            Microsoft.Synchronization.Data.DbSyncScopeDescription ScopeDesc = new Microsoft.Synchronization.Data.DbSyncScopeDescription("TestScope");
    
            Microsoft.Synchronization.Data.DbSyncTableDescription TestTable = Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncDescriptionBuilder.GetDescriptionForTable("Test", ServerConn);
    
            ScopeDesc.Tables.Add(TestTable);
    
            Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncScopeProvisioning serverConfig = new Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncScopeProvisioning(ServerConn, ScopeDesc);
    
            // serverConfig.SetCreateTableDefault(Microsoft.Synchronization.Data.DbSyncCreationOption.Skip);
            // serverConfig.ObjectPrefix = "Sync";
    
            serverConfig.Apply();
    
            Microsoft.Synchronization.Data.DbSyncScopeDescription ClientDesc = Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncDescriptionBuilder.GetDescriptionForScope("TestScope", ServerConn);
    
            Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncScopeProvisioning ClientConfig = new Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncScopeProvisioning(ClientConn, ClientDesc);
    
            ClientConfig.SetCreateTableDefault(Microsoft.Synchronization.Data.DbSyncCreationOption.CreateOrUseExisting);
    
            // ClientConfig.ObjectPrefix = "Sync";
            ClientConfig.Apply();
    
            SyncOrc.Synchronize();
    
          }
    
          catch (Exception ex)
          {
    
    
    
          }
    
          Application.Exit();
    

    Owner, Quilnet Solutions
    • Marked as answer by Quilnux Tuesday, January 25, 2011 12:43 AM
    Tuesday, January 25, 2011 12:42 AM

All replies

  • it seems you're retreiving the scope definition itself fromyou're client database when in fact you're just about to provision it itself. also, you need to provision both server and client first before you can sync.

    you can check out the documentation that get's installed with Sync Fx, there's a walkthrough/tutorial there that goes thru how to provision and sync.

    Sunday, January 23, 2011 7:17 AM
    Moderator
  • it seems you're retreiving the scope definition itself fromyou're client database when in fact you're just about to provision it itself. also, you need to provision both server and client first before you can sync.

    you can check out the documentation that get's installed with Sync Fx, there's a walkthrough/tutorial there that goes thru how to provision and sync.


    I tried looking at the walkthrough but it wasn't making much sense to me. Probably because I'm not a DBA.

    I'll look at it again today.

    Am I correct in assuming that the provisioning process is manual? (I have to construct the Sync tables myself, Sync doesn't do it for me)


    Owner, Quilnet Solutions
    Sunday, January 23, 2011 12:59 PM
  • you can simply copy the completed code at the end of each walkthrough. they are not made for dba's either.

    you have the option to construct the table structure yourself. if its already created, you can retrieve the structure as well. the walkthroughs has a sample of it as well on how to do both.

    the provisioning is automated for you, you just have to tell it which tables you want to synchronize. and provisioning has to be on both sides being synchronized.

    • Marked as answer by Quilnux Tuesday, January 25, 2011 12:42 AM
    Sunday, January 23, 2011 1:40 PM
    Moderator
  • you can simply copy the completed code at the end of each walkthrough. they are not made for dba's either.

    you have the option to construct the table structure yourself. if its already created, you can retrieve the structure as well. the walkthroughs has a sample of it as well on how to do both.

    the provisioning is automated for you, you just have to tell it which tables you want to synchronize. and provisioning has to be on both sides being synchronized.


    Yeah, the database and tables are already set up (thats the one and only thing I know how to do with DB's lol. That and adding users). I'll check out the sample for retrieving the structure.

    Both sides, ok. I was figuring just the client side (which thinking about it now doesn't make much sense to provision just the one side.)


    Owner, Quilnet Solutions
    Sunday, January 23, 2011 1:44 PM
  • the walkthroughs has a sample of it as well on how to do both.
    You must have samples that i don't have because I can't even find any samples that deal with databases at all. I only see them for metadata (in-memory) and File sync.
    Owner, Quilnet Solutions
    Monday, January 24, 2011 9:39 PM
  • Ok, this is what I have.

       Microsoft.Synchronization.SyncOrchestrator SyncOrc = new Microsoft.Synchronization.SyncOrchestrator();
    
       SqlCeConnection ServerConn = new SqlCeConnection(@"Data Source=C:\Users\<username>\Documents\Visual Studio 2010\Projects\SyncFrameTest\SyncFrameTest-SQL\Bin\Debug\ServerDatabase.sdf");
       SqlCeConnection ClientConn = new SqlCeConnection(@"Data Source=C:\Users\<username>\Documents\Visual Studio 2010\Projects\SyncFrameTest\SyncFrameTest-SQL\Bin\Debug\ClientDatabase.sdf");
    
       Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncProvider CEServerDB = new Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncProvider("Server", ServerConn);
       Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncProvider CEClientDB = new Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncProvider("Client", ClientConn);
    
       // Microsoft.Synchronization.Data.DbSyncProvider CEServerDB = new Microsoft.Synchronization.Data.DbSyncProvider();
       // Microsoft.Synchronization.Data.DbSyncProvider CEClientDB = new Microsoft.Synchronization.Data.DbSyncProvider();
    
       SyncOrc.LocalProvider = CEClientDB;
       SyncOrc.RemoteProvider = CEServerDB;
       SyncOrc.Direction = Microsoft.Synchronization.SyncDirectionOrder.DownloadAndUpload;
    
       string scopeName = CEClientDB.ScopeName;
    
       try
       {
    
        Microsoft.Synchronization.Data.DbSyncScopeDescription ScopeDesc = new Microsoft.Synchronization.Data.DbSyncScopeDescription("TestScope4");
    
        Microsoft.Synchronization.Data.DbSyncTableDescription TestTable = Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncDescriptionBuilder.GetDescriptionForTable("Test", ServerConn);
    
        ScopeDesc.Tables.Add(TestTable);
    
        Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncScopeProvisioning serverConfig = new Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncScopeProvisioning(ScopeDesc);
    
        serverConfig.SetCreateTableDefault(Microsoft.Synchronization.Data.DbSyncCreationOption.CreateOrUseExisting);
        serverConfig.ObjectPrefix = "Sync";
    
        serverConfig.Apply(ServerConn);
    
        Microsoft.Synchronization.Data.DbSyncScopeDescription ClientDesc = Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncDescriptionBuilder.GetDescriptionForScope("TestScope4", ServerConn);
    
        Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncScopeProvisioning ClientConfig = new Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncScopeProvisioning(ClientDesc);
    
        ClientConfig.ObjectPrefix = "Sync";
        ClientConfig.Apply(ClientConn);
    
        SyncOrc.Synchronize();
    
       }
    
       catch (Exception ex)
       {
    
    
    
       }
    
    
    
       Application.Exit();
    

    It seems to provision the RemoteProvider correctly (opening the CE database in SSMS shows the scope tables.)

    When I get to

    Microsoft.Synchronization.Data.DbSyncScopeDescription ClientDesc = Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncDescriptionBuilder.GetDescriptionForScope("TestScope4", ServerConn);
    

    I still get "The current operation could not be completed because the database is not provisioned for sync or you not have permissions to the sync configuration tables."

    What the heck am I doing wrong?


    Owner, Quilnet Solutions
    Monday, January 24, 2011 10:41 PM
  • I managed to get it. As usually, I was doing it wrong.

    This is the correct code for Sync Framework 2.1.

          Microsoft.Synchronization.SyncOrchestrator SyncOrc = new Microsoft.Synchronization.SyncOrchestrator();
    
          SqlCeConnection ServerConn = new SqlCeConnection(@"Data Source=C:\Users\<username>\Documents\Visual Studio 2010\Projects\SyncFrameTest\SyncFrameTest-SQL\Bin\Debug\ServerDatabase.sdf");
          SqlCeConnection ClientConn = new SqlCeConnection(@"Data Source=C:\Users\<username>\Documents\Visual Studio 2010\Projects\SyncFrameTest\SyncFrameTest-SQL\Bin\Debug\ClientDatabase.sdf");
    
          try
          {
            if (System.IO.File.Exists("ClientDatabase.sdf"))
            {
              System.IO.File.Delete("ClientDatabase.sdf");
            }
          }
          catch (Exception ex)
          { }
    
          System.Data.SqlServerCe.SqlCeEngine CEEngine = new SqlCeEngine(ClientConn.ConnectionString);
          CEEngine.CreateDatabase();
    
          CEEngine.Dispose();
    
          Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncProvider CEServerDB = new Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncProvider("TestScope", ServerConn);
          Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncProvider CEClientDB = new Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncProvider("TestScope", ClientConn);
    
          SyncOrc.LocalProvider = CEClientDB;
          SyncOrc.RemoteProvider = CEServerDB;
          SyncOrc.Direction = Microsoft.Synchronization.SyncDirectionOrder.DownloadAndUpload;
    
          try
          {
    
            Microsoft.Synchronization.Data.DbSyncScopeDescription ScopeDesc = new Microsoft.Synchronization.Data.DbSyncScopeDescription("TestScope");
    
            Microsoft.Synchronization.Data.DbSyncTableDescription TestTable = Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncDescriptionBuilder.GetDescriptionForTable("Test", ServerConn);
    
            ScopeDesc.Tables.Add(TestTable);
    
            Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncScopeProvisioning serverConfig = new Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncScopeProvisioning(ServerConn, ScopeDesc);
    
            // serverConfig.SetCreateTableDefault(Microsoft.Synchronization.Data.DbSyncCreationOption.Skip);
            // serverConfig.ObjectPrefix = "Sync";
    
            serverConfig.Apply();
    
            Microsoft.Synchronization.Data.DbSyncScopeDescription ClientDesc = Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncDescriptionBuilder.GetDescriptionForScope("TestScope", ServerConn);
    
            Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncScopeProvisioning ClientConfig = new Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncScopeProvisioning(ClientConn, ClientDesc);
    
            ClientConfig.SetCreateTableDefault(Microsoft.Synchronization.Data.DbSyncCreationOption.CreateOrUseExisting);
    
            // ClientConfig.ObjectPrefix = "Sync";
            ClientConfig.Apply();
    
            SyncOrc.Synchronize();
    
          }
    
          catch (Exception ex)
          {
    
    
    
          }
    
          Application.Exit();
    

    Owner, Quilnet Solutions
    • Marked as answer by Quilnux Tuesday, January 25, 2011 12:43 AM
    Tuesday, January 25, 2011 12:42 AM