locked
GetSchema() returns error when SyncDirection is UploadOnly

    Question

  • I am in the process of running through the N-Tier example and have run into a problem.  I have successfully run a test using Bi-Directional syncing through an asp.net webservice, however, when I try to test the UploadOnly Sync Dircection I receive the following error from the Web Service:

    "Microsoft.Synchronization.Data.SchemaException: Unable to initialize the client database, because the schema for table 'Orders' could not be retrieved by the GetSchema() method of DbServerSyncProvider. Make sure that you can establish a connection to the client database and that either the SelectIncrementalInsertsCommand property or the SelectIncrementalUpdatesCommand property of the SyncAdapter is specified correctly. " 

    Here is the constructor of the WebService.

    Public Sub New()
    _objServerProvider =
    New DbServerSyncProvider()
    Dim objBuilder As New SqlConnectionStringBuilder
    '1. Prepare server db connection and attach it to the sync agent
    objBuilder("Data Source") = "MyServer"
    objBuilder("Integrated Security") = True
    objBuilder("Initial Catalog") = "pub"

    Dim objSQLConnection As New SqlConnection(objBuilder.ConnectionString)
    _objServerProvider.Connection = objSQLConnection

    ' 2. Create sync adapter for each sync table and attach it to the agent
    Dim objOrdersBuilder As New SqlSyncAdapterBuilder
    objOrdersBuilder.Connection = objSQLConnection
    objOrdersBuilder.SyncDirection = SyncDirection.UploadOnly

    objOrdersBuilder.TableName =
    "orders"
    objOrdersBuilder.DataColumns.Add("order_id")
    objOrdersBuilder.DataColumns.Add(
    "order_date")
    objOrdersBuilder.TombstoneTableName = "orders_tombstone"
    objOrdersBuilder.TombstoneDataColumns.Add("order_id")
    objOrdersBuilder.TombstoneDataColumns.Add(
    "order_date")
    objOrdersBuilder.CreationTrackingColumn =
    "create_timestamp"
    objOrdersBuilder.UpdateTrackingColumn = "update_timestamp"
    objOrdersBuilder.DeletionTrackingColumn = "update_timestamp"
    objOrdersBuilder.UpdateOriginatorIdColumn = "update_originator_id"

    Dim objSyncAdapter As SyncAdapter = objOrdersBuilder.ToSyncAdapter
    If Not objSyncAdapter.SelectIncrementalInsertsCommand Is Nothing Then

    Dim objSQLParameter As SqlParameter = CType(objSyncAdapter.SelectIncrementalInsertsCommand.Parameters("@sync_last_received_anchor"), SqlParameter)
    objSQLParameter.DbType = DbType.Binary
    objSyncAdapter.SelectIncrementalInsertsCommand.Parameters(
    "@sync_last_received_anchor") = objSQLParameter


    objSQLParameter = (
    CType(objSyncAdapter.SelectIncrementalInsertsCommand.Parameters("@sync_new_received_anchor"), SqlParameter))objSQLParameter.DbType = DbType.Binary
    objSyncAdapter.SelectIncrementalInsertsCommand.Parameters(
    "@sync_new_received_anchor") = objSQLParameter
    End If

     _objServerProvider.SyncAdapters.Add(objSyncAdapter)

    ' select new anchor command
    Dim objAnchorCmd = New SqlCommand
    objAnchorCmd.CommandType = CommandType.Text
    objAnchorCmd.CommandText =
    "SELECT @@DBTS"
    _objServerProvider.SelectNewAnchorCommand = objAnchorCmd

    Dim objMappingCmd As New SqlCommand("SELECT 1", objSQLConnection)
    objMappingCmd.CommandType = CommandType.Text
    objMappingCmd.Parameters.Add(SyncSession.SyncClientId, SqlDbType.UniqueIdentifier)
    _objServerProvider.SelectClientIdCommand = objMappingCmd
    End Sub

    Does anyone have any thoughts as to why this error is occuring?

    • Moved by Max Wang_Chinasoft Friday, April 22, 2011 11:06 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Thursday, March 22, 2007 6:29 PM

Answers


  • Hi

    Try to set UploadOnly on the SyncTable object instead. When you set it on the  SyncAdapterBuidler, the select incremental commands are not generated by the builder. These commands are used to get the table schema from the database. Since these are missing you are getting the schema error.

    Thanks

    Thursday, March 22, 2007 6:59 PM