locked
SyncOrchestrator.Synchronize() causes ArgumentException RRS feed

  • Question

  • Hi everyone!

    I`m new to SyncFx. I just took a sample code from here, and changed connection strings to my SQL Express databases, created especially for this scenario.

    When I run the sample, SyncOrchestrator.Synchronize() method throws ArgumentException:

    System.ArgumentException was unhandled

      Message=Cannot add the SyncAdapter to the SyncAdapterCollection. A SyncAdapter for table 'Contacts' already exists.

      Source=Microsoft.Synchronization

      StackTrace:

           at Microsoft.Synchronization.Data.DbSyncAdapterCollection.ValidateTableName(Int32 index, String value)

           at Microsoft.Synchronization.Data.DbSyncAdapterCollection.Validate(Int32 index, DbSyncAdapter value)

           at Microsoft.Synchronization.Data.DbSyncAdapterCollection.InsertItem(Int32 index, DbSyncAdapter item)

           at System.Collections.ObjectModel.Collection`1.Add(T item)

           at Microsoft.Synchronization.Data.SqlServer.SqlSyncProvider.Configure()

           at Microsoft.Synchronization.Data.SqlServer.SqlSyncProvider.BeginSession(SyncProviderPosition position, SyncSessionContext syncSessionContext)

           at Microsoft.Synchronization.KnowledgeProviderProxy.BeginSession(SYNC_PROVIDER_ROLE providerRole, ISyncSessionState pSessionState)

           at Microsoft.Synchronization.CoreInterop.ISyncSession.Start(CONFLICT_RESOLUTION_POLICY resolutionPolicy, _SYNC_SESSION_STATISTICS& pSyncSessionStatistics)

           at Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWaySyncHelper(SyncIdFormatGroup sourceIdFormats, SyncIdFormatGroup destinationIdFormats, KnowledgeSyncProviderConfiguration destinationConfiguration, SyncCallbacks DestinationCallbacks, ISyncProvider sourceProxy, ISyncProvider destinationProxy, ChangeDataAdapter callbackChangeDataAdapter, SyncDataConverter conflictDataConverter, Int32& changesApplied, Int32& changesFailed)

           at Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWayKnowledgeSync(SyncDataConverter sourceConverter, SyncDataConverter destinationConverter, SyncProvider sourceProvider, SyncProvider destinationProvider, Int32& changesApplied, Int32& changesFailed)

           at Microsoft.Synchronization.KnowledgeSyncOrchestrator.Synchronize()

           at Microsoft.Synchronization.SyncOrchestrator.Synchronize()

           at SyncFrameworkSample.Program.Main(String[] args) in C:\Documents and Settings\yermakovich\My Documents\Visual Studio 2010\Projects\SyncFrameworkSample\SyncFrameworkSample\Program.cs:line 77

           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)

           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)

           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

           at System.Threading.ThreadHelper.ThreadStart()


     

    I recreated databases, but error still appears. Any ideas?

     

     

    Friday, March 11, 2011 2:38 PM

Answers

  • check your code to make sure you didnt add the same table twice...also the sample you referenced above is for the offline providers using SyncAgent whereas the error you posted above is for SyncOrchestrator.
    Friday, March 11, 2011 4:10 PM
  • you need to provision on both sides, local and remote.

    did you just mask the conn_str? both your localprovider and remoteprovider are using to the same connection string.

    Friday, March 11, 2011 5:28 PM

All replies

  • check your code to make sure you didnt add the same table twice...also the sample you referenced above is for the offline providers using SyncAgent whereas the error you posted above is for SyncOrchestrator.
    Friday, March 11, 2011 4:10 PM
  • check your code to make sure you didnt add the same table twice...also the sample you referenced above is for the offline providers using SyncAgent whereas the error you posted above is for SyncOrchestrator.

    Sorry, I mentioned this sample. Link updated.

    Yes, you are right. I found that the same table was added twice!

    But now I get another error...

     

    Microsoft.Synchronization.Data.DbNotProvisionedException was unhandled

      Message=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.

      Source=Microsoft.Synchronization

      StackTrace:

           at Microsoft.Synchronization.Data.SqlServer.SqlManagementUtils.VerifyRuntimeVersionExceedsSchema(SqlConnection connection, String objectPrefix, String objectSchema, Boolean throwWhenNotProvisioned)

           at Microsoft.Synchronization.Data.SqlServer.SqlSyncProvider.Configure()

           at Microsoft.Synchronization.Data.SqlServer.SqlSyncProvider.BeginSession(SyncProviderPosition position, SyncSessionContext syncSessionContext)

           at Microsoft.Synchronization.KnowledgeProviderProxy.BeginSession(SYNC_PROVIDER_ROLE providerRole, ISyncSessionState pSessionState)

           at Microsoft.Synchronization.CoreInterop.ISyncSession.Start(CONFLICT_RESOLUTION_POLICY resolutionPolicy, _SYNC_SESSION_STATISTICS& pSyncSessionStatistics)

           at Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWaySyncHelper(SyncIdFormatGroup sourceIdFormats, SyncIdFormatGroup destinationIdFormats, KnowledgeSyncProviderConfiguration destinationConfiguration, SyncCallbacks DestinationCallbacks, ISyncProvider sourceProxy, ISyncProvider destinationProxy, ChangeDataAdapter callbackChangeDataAdapter, SyncDataConverter conflictDataConverter, Int32& changesApplied, Int32& changesFailed)

           at Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWayKnowledgeSync(SyncDataConverter sourceConverter, SyncDataConverter destinationConverter, SyncProvider sourceProvider, SyncProvider destinationProvider, Int32& changesApplied, Int32& changesFailed)

           at Microsoft.Synchronization.KnowledgeSyncOrchestrator.Synchronize()

           at Microsoft.Synchronization.SyncOrchestrator.Synchronize()

           at SyncFrameworkSample.Program.Main(String[] args) in C:\Documents and Settings\yermakovich\My Documents\Visual Studio 2010\Projects\SyncFrameworkSample\SyncFrameworkSample\Program.cs:line 46

           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)

           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)

           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

           at System.Threading.ThreadHelper.ThreadStart()

     

    Database was provisioned. Connections under admin accounts. Change tracking enabled on the source database (one-way sync).

     

    Friday, March 11, 2011 5:01 PM
  • can you post some code snippets?
    Friday, March 11, 2011 5:07 PM
  • Sure, here is my code

     

          var sourceConnection = new SqlConnection("conn_str");
          var destConnection =
            new SqlConnection("conn_str");
    
          var scopeDesc = new DbSyncScopeDescription("contact");
    
          var columnsToInclude = new Collection<string>();
          columnsToInclude.Add("Id");
          columnsToInclude.Add("ContactDateUtc");
          DbSyncTableDescription customerContactDescription =
            SqlSyncDescriptionBuilder.GetDescriptionForTable("Contacts, columnsToInclude, sourceConnection);
    
          scopeDesc.Tables.Add(customerContactDescription);
    
          var serverConfig = new SqlSyncScopeProvisioning(sourceConnection, scopeDesc);
    
          // Configure the scope and change-tracking infrastructure.
          serverConfig.Apply();
    
          var syncOrchestrator = new SyncOrchestrator();
          syncOrchestrator.LocalProvider = new SqlSyncProvider(scopeDesc.ScopeName, sourceConnection);
          syncOrchestrator.RemoteProvider = new SqlSyncProvider(scopeDesc.ScopeName, destConnection);
          syncOrchestrator.Direction = SyncDirectionOrder.Upload;
          syncOrchestrator.Synchronize();
    

     

    Friday, March 11, 2011 5:21 PM
  • you need to provision on both sides, local and remote.

    did you just mask the conn_str? both your localprovider and remoteprovider are using to the same connection string.

    Friday, March 11, 2011 5:28 PM
  • Really? I didn`t realize that I need to provision on both sides. Thank you very much.

    P.S. yes, I mask connection strings.

    Friday, March 11, 2011 8:54 PM