Solved

How to Find Invalid Cast Exception in Microsoft SyncAgent?

Posted on 2014-10-07
4
297 Views
Last Modified: 2014-10-18
I was able to set up a synchronization between a SQL Server Express 2008 R2 database and an empty SQL Server CE 3.5.1 database. The wizard populated the client db just fine. It did, however, make a datetime variable into a character variable. I manually changed all of them to datetime. When I try to synchronize, I get the following error:

System.InvalidCastException was unhandled
  Message=Microsoft.Synchronization.Data.ClientSyncProvider
  Source=Microsoft.Synchronization.Data
  StackTrace:
       at Microsoft.Synchronization.SyncAgent.set_LocalProvider(SyncProvider value)
       at HHGCMS.HHGCMSSyncAgent.InitializeSyncProviders() in D:\VisualStudio2005\Projects\HHGCMS\HHGCMS.Designer.vb:line 63
       at HHGCMS.HHGCMSSyncAgent..ctor() in D:\VisualStudio2005\Projects\HHGCMS\HHGCMS.Designer.vb:line 42
       at HHGCMS.frmMain.btnSynchronize_Click(Object sender, EventArgs e) in D:\VisualStudio2005\Projects\HHGCMS\frmMain.vb:line 5
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at HHGCMS.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(Assembly 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)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

The code to attempt the synchronization is simple:
        Dim HHGCMSSyncAgent As New HHGCMSSyncAgent
        Dim HHGCMSSyncStat As Microsoft.Synchronization.Data.SyncStatistics = HHGCMSSyncAgent.Synchronize()

Open in new window


I have attached a Word file which shows screen shots of the two table definitions. As far as I can tell, everything matches.

OS: Windows 7
IDE: VS2010

Question: How do I go about finding the invalid cast?
Table-Definitions.docx
0
Comment
Question by:rkulp
  • 3
4 Comments
 
LVL 15

Expert Comment

by:ChloesDad
ID: 40368931
These are the three key lines in the stack trace of the error

at HHGCMS.HHGCMSSyncAgent.InitializeSyncProviders() in D:\VisualStudio2005\Projects\HHGCMS\HHGCMS.Designer.vb:line 63
        at HHGCMS.HHGCMSSyncAgent..ctor() in D:\VisualStudio2005\Projects\HHGCMS\HHGCMS.Designer.vb:line 42
        at HHGCMS.frmMain.btnSynchronize_Click(Object sender, EventArgs e) in D:\VisualStudio2005\Projects\HHGCMS\frmMain.vb:line 5

can you post the HHGCMS.* from your project
0
 
LVL 1

Author Comment

by:rkulp
ID: 40369243
Thank you, CloesDad. I had looked at those lines but didn't see how they led me to the solution. Hopefully, you can. Here are the three lines followed by the entire designer code:

frmMain.vb: line 5:          Dim HHGCMSSyncAgent As New HHGCMSSyncAgent

Designer.vb: line 42:          Me.InitializeSyncProviders

 which is part of:

    Public Sub New()
        MyBase.New
        Me.InitializeSyncProviders
        Me.InitializeSyncTables
        Me.OnInitialized
    End Sub

Open in new window


Designer.vb: line 63:          Me.LocalProvider = New HHGCMSClientSyncProvider()
 which is part of:
    <System.Diagnostics.DebuggerNonUserCodeAttribute()>  _
    Private Sub InitializeSyncProviders()
        'Create SyncProviders.
        Me.RemoteProvider = New HHGCMSServerSyncProvider()
        Me.LocalProvider = New HHGCMSClientSyncProvider()
    End Sub

Open in new window


Entire HHGCMS.Designer.vb:
'------------------------------------------------------------------------------
' <auto-generated>
'     This code was generated by a tool.
'     Runtime Version:4.0.30319.18444
'
'     Changes to this file may cause incorrect behavior and will be lost if
'     the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------

Option Strict Off
Option Explicit On



Partial Public Class HHGCMSClientSyncProvider
    Inherits Microsoft.Synchronization.Data.SqlServerCe.SqlCeClientSyncProvider
    
    Public Sub New()
        MyBase.New
        Me.ConnectionString = ""
    End Sub
    
    Public Sub New(ByVal connectionString As String)
        MyBase.New
        Me.ConnectionString = connectionString
    End Sub
End Class

Partial Public Class HHGCMSSyncAgent
    Inherits Microsoft.Synchronization.SyncAgent
    
    Private _globalSyncGroup As Microsoft.Synchronization.Data.SyncGroup
    
    Private _itemsSyncTable As ItemsSyncTable
    
    Partial Private Sub OnInitialized()
    End Sub
    
    Public Sub New()
        MyBase.New
        Me.InitializeSyncProviders
        Me.InitializeSyncTables
        Me.OnInitialized
    End Sub
    
    <System.Diagnostics.DebuggerNonUserCodeAttribute()>  _
    Public Property Items() As ItemsSyncTable
        Get
            Return Me._itemsSyncTable
        End Get
        Set
            Me.Configuration.SyncTables.Remove(Me._itemsSyncTable)
            Me._itemsSyncTable = value
            Me.Configuration.SyncTables.Add(Me._itemsSyncTable)
        End Set
    End Property
    
    <System.Diagnostics.DebuggerNonUserCodeAttribute()>  _
    Private Sub InitializeSyncProviders()
        'Create SyncProviders.
        Me.RemoteProvider = New HHGCMSServerSyncProvider()
        Me.LocalProvider = New HHGCMSClientSyncProvider()
    End Sub
    
    <System.Diagnostics.DebuggerNonUserCodeAttribute()>  _
    Private Sub InitializeSyncTables()
        'Create a global SyncGroup.
        Me._globalSyncGroup = New Microsoft.Synchronization.Data.SyncGroup("HHGCMSGlobalSyncGroup")
        'Create SyncTables.
        Me._itemsSyncTable = New ItemsSyncTable()
        Me._itemsSyncTable.SyncGroup = _globalSyncGroup
        Me.Configuration.SyncTables.Add(Me._itemsSyncTable)
    End Sub
    
    Partial Public Class ItemsSyncTable
        Inherits Microsoft.Synchronization.Data.SyncTable
        
        Partial Private Sub OnInitialized()
        End Sub
        
        Public Sub New()
            MyBase.New
            Me.InitializeTableOptions
            Me.OnInitialized
        End Sub
        
        <System.Diagnostics.DebuggerNonUserCodeAttribute()>  _
        Private Sub InitializeTableOptions()
            Me.TableName = "Items"
            Me.CreationOption = Microsoft.Synchronization.Data.TableCreationOption.DropExistingOrCreateNewTable
        End Sub
    End Class
End Class


Partial Public Class ItemsSyncAdapter
    Inherits Microsoft.Synchronization.Data.Server.SyncAdapter
    
    Partial Private Sub OnInitialized()
    End Sub
    
    Public Sub New()
        MyBase.New
        Me.InitializeCommands
        Me.InitializeAdapterProperties
        Me.OnInitialized
    End Sub
    
    <System.Diagnostics.DebuggerNonUserCodeAttribute()>  _
    Private Sub InitializeCommands()
        'ItemsSyncTableInsertCommand command.
        Me.InsertCommand = New System.Data.SqlClient.SqlCommand()
        Me.InsertCommand.CommandText = " SET IDENTITY_INSERT dbo.Items ON ;WITH CHANGE_TRACKING_CONTEXT (@sync_client_id_"& _ 
            "binary) INSERT INTO dbo.Items ([ItemNbr], [ItemName], [RoomName], [Category], [Q"& _ 
            "uantity], [PurchasePrice], [DatePurchased], [PlacePurchased], [Make], [Model], ["& _ 
            "SerialNbr], [Brand], [Description], [ReplacementCost], [ItemClaimed], [DateClaim"& _ 
            "ed], [Approved], [DateApproved], [AmountPaid], [DatePaid], [ClaimNbr]) VALUES (@"& _ 
            "ItemNbr, @ItemName, @RoomName, @Category, @Quantity, @PurchasePrice, @DatePurcha"& _ 
            "sed, @PlacePurchased, @Make, @Model, @SerialNbr, @Brand, @Description, @Replacem"& _ 
            "entCost, @ItemClaimed, @DateClaimed, @Approved, @DateApproved, @AmountPaid, @Dat"& _ 
            "ePaid, @ClaimNbr) SET @sync_row_count = @@rowcount; IF CHANGE_TRACKING_MIN_VALID"& _ 
            "_VERSION(object_id(N'dbo.Items')) > @sync_last_received_anchor RAISERROR (N'SQL "& _ 
            "Server Change Tracking has cleaned up tracking information for table ''%s''. To "& _ 
            "recover from this error, the client must reinitialize its local database and try"& _ 
            " again',16,3,N'dbo.Items')  SET IDENTITY_INSERT dbo.Items OFF "
        Me.InsertCommand.CommandType = System.Data.CommandType.Text
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_client_id_binary", System.Data.SqlDbType.VarBinary))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ItemNbr", System.Data.SqlDbType.Int))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ItemName", System.Data.SqlDbType.VarChar))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RoomName", System.Data.SqlDbType.NVarChar))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Category", System.Data.SqlDbType.NVarChar))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Quantity", System.Data.SqlDbType.Int))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@PurchasePrice", System.Data.SqlDbType.Money))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@DatePurchased", System.Data.SqlDbType.Date))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@PlacePurchased", System.Data.SqlDbType.NVarChar))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Make", System.Data.SqlDbType.NVarChar))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Model", System.Data.SqlDbType.NVarChar))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@SerialNbr", System.Data.SqlDbType.NVarChar))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Brand", System.Data.SqlDbType.NVarChar))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Description", System.Data.SqlDbType.NVarChar))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ReplacementCost", System.Data.SqlDbType.Money))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ItemClaimed", System.Data.SqlDbType.Bit))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@DateClaimed", System.Data.SqlDbType.Date))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Approved", System.Data.SqlDbType.Bit))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@DateApproved", System.Data.SqlDbType.Date))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@AmountPaid", System.Data.SqlDbType.Money))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@DatePaid", System.Data.SqlDbType.Date))
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ClaimNbr", System.Data.SqlDbType.NVarChar))
        Dim insertcommand_sync_row_countParameter As System.Data.SqlClient.SqlParameter = New System.Data.SqlClient.SqlParameter("@sync_row_count", System.Data.SqlDbType.Int)
        insertcommand_sync_row_countParameter.Direction = System.Data.ParameterDirection.Output
        Me.InsertCommand.Parameters.Add(insertcommand_sync_row_countParameter)
        Me.InsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_last_received_anchor", System.Data.SqlDbType.BigInt))
        'ItemsSyncTableDeleteCommand command.
        Me.DeleteCommand = New System.Data.SqlClient.SqlCommand()
        Me.DeleteCommand.CommandText = ";WITH CHANGE_TRACKING_CONTEXT (@sync_client_id_binary) DELETE dbo.Items FROM dbo."& _ 
            "Items JOIN CHANGETABLE(VERSION dbo.Items, ([ItemNbr]), (@ItemNbr)) CT  ON CT.[It"& _ 
            "emNbr] = dbo.Items.[ItemNbr] WHERE (@sync_force_write = 1 OR CT.SYS_CHANGE_VERSI"& _ 
            "ON IS NULL OR CT.SYS_CHANGE_VERSION <= @sync_last_received_anchor OR (CT.SYS_CHA"& _ 
            "NGE_CONTEXT IS NOT NULL AND CT.SYS_CHANGE_CONTEXT = @sync_client_id_binary)) SET"& _ 
            " @sync_row_count = @@rowcount; IF CHANGE_TRACKING_MIN_VALID_VERSION(object_id(N'"& _ 
            "dbo.Items')) > @sync_last_received_anchor RAISERROR (N'SQL Server Change Trackin"& _ 
            "g has cleaned up tracking information for table ''%s''. To recover from this err"& _ 
            "or, the client must reinitialize its local database and try again',16,3,N'dbo.It"& _ 
            "ems') "
        Me.DeleteCommand.CommandType = System.Data.CommandType.Text
        Me.DeleteCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_client_id_binary", System.Data.SqlDbType.VarBinary))
        Me.DeleteCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ItemNbr", System.Data.SqlDbType.Int))
        Me.DeleteCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_force_write", System.Data.SqlDbType.Bit))
        Me.DeleteCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_last_received_anchor", System.Data.SqlDbType.BigInt))
        Dim deletecommand_sync_row_countParameter As System.Data.SqlClient.SqlParameter = New System.Data.SqlClient.SqlParameter("@sync_row_count", System.Data.SqlDbType.Int)
        deletecommand_sync_row_countParameter.Direction = System.Data.ParameterDirection.Output
        Me.DeleteCommand.Parameters.Add(deletecommand_sync_row_countParameter)
        'ItemsSyncTableUpdateCommand command.
        Me.UpdateCommand = New System.Data.SqlClient.SqlCommand()
        Me.UpdateCommand.CommandText = ";WITH CHANGE_TRACKING_CONTEXT (@sync_client_id_binary) UPDATE dbo.Items SET [Item"& _ 
            "Name] = @ItemName, [RoomName] = @RoomName, [Category] = @Category, [Quantity] = "& _ 
            "@Quantity, [PurchasePrice] = @PurchasePrice, [DatePurchased] = @DatePurchased, ["& _ 
            "PlacePurchased] = @PlacePurchased, [Make] = @Make, [Model] = @Model, [SerialNbr]"& _ 
            " = @SerialNbr, [Brand] = @Brand, [Description] = @Description, [ReplacementCost]"& _ 
            " = @ReplacementCost, [ItemClaimed] = @ItemClaimed, [DateClaimed] = @DateClaimed,"& _ 
            " [Approved] = @Approved, [DateApproved] = @DateApproved, [AmountPaid] = @AmountP"& _ 
            "aid, [DatePaid] = @DatePaid, [ClaimNbr] = @ClaimNbr FROM dbo.Items  JOIN CHANGET"& _ 
            "ABLE(VERSION dbo.Items, ([ItemNbr]), (@ItemNbr)) CT  ON CT.[ItemNbr] = dbo.Items"& _ 
            ".[ItemNbr] WHERE (@sync_force_write = 1 OR CT.SYS_CHANGE_VERSION IS NULL OR CT.S"& _ 
            "YS_CHANGE_VERSION <= @sync_last_received_anchor OR (CT.SYS_CHANGE_CONTEXT IS NOT"& _ 
            " NULL AND CT.SYS_CHANGE_CONTEXT = @sync_client_id_binary)) SET @sync_row_count ="& _ 
            " @@rowcount; IF CHANGE_TRACKING_MIN_VALID_VERSION(object_id(N'dbo.Items')) > @sy"& _ 
            "nc_last_received_anchor RAISERROR (N'SQL Server Change Tracking has cleaned up t"& _ 
            "racking information for table ''%s''. To recover from this error, the client mus"& _ 
            "t reinitialize its local database and try again',16,3,N'dbo.Items') "
        Me.UpdateCommand.CommandType = System.Data.CommandType.Text
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ItemName", System.Data.SqlDbType.VarChar))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RoomName", System.Data.SqlDbType.NVarChar))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Category", System.Data.SqlDbType.NVarChar))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Quantity", System.Data.SqlDbType.Int))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@PurchasePrice", System.Data.SqlDbType.Money))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@DatePurchased", System.Data.SqlDbType.Date))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@PlacePurchased", System.Data.SqlDbType.NVarChar))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Make", System.Data.SqlDbType.NVarChar))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Model", System.Data.SqlDbType.NVarChar))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@SerialNbr", System.Data.SqlDbType.NVarChar))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Brand", System.Data.SqlDbType.NVarChar))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Description", System.Data.SqlDbType.NVarChar))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ReplacementCost", System.Data.SqlDbType.Money))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ItemClaimed", System.Data.SqlDbType.Bit))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@DateClaimed", System.Data.SqlDbType.Date))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Approved", System.Data.SqlDbType.Bit))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@DateApproved", System.Data.SqlDbType.Date))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@AmountPaid", System.Data.SqlDbType.Money))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@DatePaid", System.Data.SqlDbType.Date))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ClaimNbr", System.Data.SqlDbType.NVarChar))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ItemNbr", System.Data.SqlDbType.Int))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_force_write", System.Data.SqlDbType.Bit))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_last_received_anchor", System.Data.SqlDbType.BigInt))
        Me.UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_client_id_binary", System.Data.SqlDbType.VarBinary))
        Dim updatecommand_sync_row_countParameter As System.Data.SqlClient.SqlParameter = New System.Data.SqlClient.SqlParameter("@sync_row_count", System.Data.SqlDbType.Int)
        updatecommand_sync_row_countParameter.Direction = System.Data.ParameterDirection.Output
        Me.UpdateCommand.Parameters.Add(updatecommand_sync_row_countParameter)
        'ItemsSyncTableSelectConflictDeletedRowsCommand command.
        Me.SelectConflictDeletedRowsCommand = New System.Data.SqlClient.SqlCommand()
        Me.SelectConflictDeletedRowsCommand.CommandText = "SELECT CT.[ItemNbr], CT.SYS_CHANGE_CONTEXT, CT.SYS_CHANGE_VERSION FROM CHANGETABL"& _ 
            "E(CHANGES dbo.Items, @sync_last_received_anchor) CT WHERE (CT.[ItemNbr] = @ItemN"& _ 
            "br AND CT.SYS_CHANGE_OPERATION = 'D')"
        Me.SelectConflictDeletedRowsCommand.CommandType = System.Data.CommandType.Text
        Me.SelectConflictDeletedRowsCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_last_received_anchor", System.Data.SqlDbType.BigInt))
        Me.SelectConflictDeletedRowsCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ItemNbr", System.Data.SqlDbType.Int))
        'ItemsSyncTableSelectConflictUpdatedRowsCommand command.
        Me.SelectConflictUpdatedRowsCommand = New System.Data.SqlClient.SqlCommand()
        Me.SelectConflictUpdatedRowsCommand.CommandText = "SELECT dbo.Items.[ItemNbr], [ItemName], [RoomName], [Category], [Quantity], [Purc"& _ 
            "hasePrice], [DatePurchased], [PlacePurchased], [Make], [Model], [SerialNbr], [Br"& _ 
            "and], [Description], [ReplacementCost], [ItemClaimed], [DateClaimed], [Approved]"& _ 
            ", [DateApproved], [AmountPaid], [DatePaid], [ClaimNbr], CT.SYS_CHANGE_CONTEXT, C"& _ 
            "T.SYS_CHANGE_VERSION FROM dbo.Items JOIN CHANGETABLE(VERSION dbo.Items, ([ItemNb"& _ 
            "r]), (@ItemNbr)) CT  ON CT.[ItemNbr] = dbo.Items.[ItemNbr]"
        Me.SelectConflictUpdatedRowsCommand.CommandType = System.Data.CommandType.Text
        Me.SelectConflictUpdatedRowsCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ItemNbr", System.Data.SqlDbType.Int))
        'ItemsSyncTableSelectIncrementalInsertsCommand command.
        Me.SelectIncrementalInsertsCommand = New System.Data.SqlClient.SqlCommand()
        Me.SelectIncrementalInsertsCommand.CommandText = "IF @sync_initialized = 0 SELECT dbo.Items.[ItemNbr], [ItemName], [RoomName], [Cat"& _ 
            "egory], [Quantity], [PurchasePrice], [DatePurchased], [PlacePurchased], [Make], "& _ 
            "[Model], [SerialNbr], [Brand], [Description], [ReplacementCost], [ItemClaimed], "& _ 
            "[DateClaimed], [Approved], [DateApproved], [AmountPaid], [DatePaid], [ClaimNbr] "& _ 
            "FROM dbo.Items LEFT OUTER JOIN CHANGETABLE(CHANGES dbo.Items, @sync_last_receive"& _ 
            "d_anchor) CT ON CT.[ItemNbr] = dbo.Items.[ItemNbr] WHERE (CT.SYS_CHANGE_CONTEXT "& _ 
            "IS NULL OR CT.SYS_CHANGE_CONTEXT <> @sync_client_id_binary) ELSE  BEGIN SELECT d"& _ 
            "bo.Items.[ItemNbr], [ItemName], [RoomName], [Category], [Quantity], [PurchasePri"& _ 
            "ce], [DatePurchased], [PlacePurchased], [Make], [Model], [SerialNbr], [Brand], ["& _ 
            "Description], [ReplacementCost], [ItemClaimed], [DateClaimed], [Approved], [Date"& _ 
            "Approved], [AmountPaid], [DatePaid], [ClaimNbr] FROM dbo.Items JOIN CHANGETABLE("& _ 
            "CHANGES dbo.Items, @sync_last_received_anchor) CT ON CT.[ItemNbr] = dbo.Items.[I"& _ 
            "temNbr] WHERE (CT.SYS_CHANGE_OPERATION = 'I' AND CT.SYS_CHANGE_CREATION_VERSION "& _ 
            " <= @sync_new_received_anchor AND (CT.SYS_CHANGE_CONTEXT IS NULL OR CT.SYS_CHANG"& _ 
            "E_CONTEXT <> @sync_client_id_binary)); IF CHANGE_TRACKING_MIN_VALID_VERSION(obje"& _ 
            "ct_id(N'dbo.Items')) > @sync_last_received_anchor RAISERROR (N'SQL Server Change"& _ 
            " Tracking has cleaned up tracking information for table ''%s''. To recover from "& _ 
            "this error, the client must reinitialize its local database and try again',16,3,"& _ 
            "N'dbo.Items')  END "
        Me.SelectIncrementalInsertsCommand.CommandType = System.Data.CommandType.Text
        Me.SelectIncrementalInsertsCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_initialized", System.Data.SqlDbType.Bit))
        Me.SelectIncrementalInsertsCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_last_received_anchor", System.Data.SqlDbType.BigInt))
        Me.SelectIncrementalInsertsCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_client_id_binary", System.Data.SqlDbType.VarBinary))
        Me.SelectIncrementalInsertsCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_new_received_anchor", System.Data.SqlDbType.BigInt))
        'ItemsSyncTableSelectIncrementalDeletesCommand command.
        Me.SelectIncrementalDeletesCommand = New System.Data.SqlClient.SqlCommand()
        Me.SelectIncrementalDeletesCommand.CommandText = "IF @sync_initialized > 0  BEGIN SELECT CT.[ItemNbr] FROM CHANGETABLE(CHANGES dbo."& _ 
            "Items, @sync_last_received_anchor) CT WHERE (CT.SYS_CHANGE_OPERATION = 'D' AND C"& _ 
            "T.SYS_CHANGE_VERSION <= @sync_new_received_anchor AND (CT.SYS_CHANGE_CONTEXT IS "& _ 
            "NULL OR CT.SYS_CHANGE_CONTEXT <> @sync_client_id_binary)); IF CHANGE_TRACKING_MI"& _ 
            "N_VALID_VERSION(object_id(N'dbo.Items')) > @sync_last_received_anchor RAISERROR "& _ 
            "(N'SQL Server Change Tracking has cleaned up tracking information for table ''%s"& _ 
            "''. To recover from this error, the client must reinitialize its local database "& _ 
            "and try again',16,3,N'dbo.Items')  END "
        Me.SelectIncrementalDeletesCommand.CommandType = System.Data.CommandType.Text
        Me.SelectIncrementalDeletesCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_initialized", System.Data.SqlDbType.Bit))
        Me.SelectIncrementalDeletesCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_last_received_anchor", System.Data.SqlDbType.BigInt))
        Me.SelectIncrementalDeletesCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_new_received_anchor", System.Data.SqlDbType.BigInt))
        Me.SelectIncrementalDeletesCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_client_id_binary", System.Data.SqlDbType.VarBinary))
        'ItemsSyncTableSelectIncrementalUpdatesCommand command.
        Me.SelectIncrementalUpdatesCommand = New System.Data.SqlClient.SqlCommand()
        Me.SelectIncrementalUpdatesCommand.CommandText = "IF @sync_initialized > 0  BEGIN SELECT dbo.Items.[ItemNbr], [ItemName], [RoomName"& _ 
            "], [Category], [Quantity], [PurchasePrice], [DatePurchased], [PlacePurchased], ["& _ 
            "Make], [Model], [SerialNbr], [Brand], [Description], [ReplacementCost], [ItemCla"& _ 
            "imed], [DateClaimed], [Approved], [DateApproved], [AmountPaid], [DatePaid], [Cla"& _ 
            "imNbr] FROM dbo.Items JOIN CHANGETABLE(CHANGES dbo.Items, @sync_last_received_an"& _ 
            "chor) CT ON CT.[ItemNbr] = dbo.Items.[ItemNbr] WHERE (CT.SYS_CHANGE_OPERATION = "& _ 
            "'U' AND CT.SYS_CHANGE_VERSION <= @sync_new_received_anchor AND (CT.SYS_CHANGE_CO"& _ 
            "NTEXT IS NULL OR CT.SYS_CHANGE_CONTEXT <> @sync_client_id_binary)); IF CHANGE_TR"& _ 
            "ACKING_MIN_VALID_VERSION(object_id(N'dbo.Items')) > @sync_last_received_anchor R"& _ 
            "AISERROR (N'SQL Server Change Tracking has cleaned up tracking information for t"& _ 
            "able ''%s''. To recover from this error, the client must reinitialize its local "& _ 
            "database and try again',16,3,N'dbo.Items')  END "
        Me.SelectIncrementalUpdatesCommand.CommandType = System.Data.CommandType.Text
        Me.SelectIncrementalUpdatesCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_initialized", System.Data.SqlDbType.Bit))
        Me.SelectIncrementalUpdatesCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_last_received_anchor", System.Data.SqlDbType.BigInt))
        Me.SelectIncrementalUpdatesCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_new_received_anchor", System.Data.SqlDbType.BigInt))
        Me.SelectIncrementalUpdatesCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@sync_client_id_binary", System.Data.SqlDbType.VarBinary))
    End Sub
    
    <System.Diagnostics.DebuggerNonUserCodeAttribute()>  _
    Private Sub InitializeAdapterProperties()
        Me.TableName = "Items"
    End Sub
End Class

Partial Public Class HHGCMSServerSyncProvider
    Inherits Microsoft.Synchronization.Data.Server.DbServerSyncProvider
    
    Private _itemsSyncAdapter As ItemsSyncAdapter
    
    Partial Private Sub OnInitialized()
    End Sub
    
    Public Sub New()
        MyBase.New
        Dim connectionString As String = Global.HHGCMS.My.MySettings.Default.ServerHouseholdInventoryConnectionString
        Me.InitializeConnection(connectionString)
        Me.InitializeSyncAdapters
        Me.InitializeNewAnchorCommand
        Me.OnInitialized
    End Sub
    
    Public Sub New(ByVal connectionString As String)
        MyBase.New
        Me.InitializeConnection(connectionString)
        Me.InitializeSyncAdapters
        Me.InitializeNewAnchorCommand
        Me.OnInitialized
    End Sub
    
    <System.Diagnostics.DebuggerNonUserCodeAttribute()>  _
    Public Property ItemsSyncAdapter() As ItemsSyncAdapter
        Get
            Return Me._itemsSyncAdapter
        End Get
        Set
            Me._itemsSyncAdapter = value
        End Set
    End Property
    
    <System.Diagnostics.DebuggerNonUserCodeAttribute()>  _
    Private Sub InitializeConnection(ByVal connectionString As String)
        Me.Connection = New System.Data.SqlClient.SqlConnection(connectionString)
    End Sub
    
    <System.Diagnostics.DebuggerNonUserCodeAttribute()>  _
    Private Sub InitializeSyncAdapters()
        'Create SyncAdapters.
        Me._itemsSyncAdapter = New ItemsSyncAdapter()
        Me.SyncAdapters.Add(Me._itemsSyncAdapter)
    End Sub
    
    <System.Diagnostics.DebuggerNonUserCodeAttribute()>  _
    Private Sub InitializeNewAnchorCommand()
        'selectNewAnchorCmd command.
        Me.SelectNewAnchorCommand = New System.Data.SqlClient.SqlCommand()
        Me.SelectNewAnchorCommand.CommandText = "Select @sync_new_received_anchor = CHANGE_TRACKING_CURRENT_VERSION()"
        Me.SelectNewAnchorCommand.CommandType = System.Data.CommandType.Text
        Dim selectnewanchorcommand_sync_new_received_anchorParameter As System.Data.SqlClient.SqlParameter = New System.Data.SqlClient.SqlParameter("@sync_new_received_anchor", System.Data.SqlDbType.BigInt)
        selectnewanchorcommand_sync_new_received_anchorParameter.Direction = System.Data.ParameterDirection.Output
        Me.SelectNewAnchorCommand.Parameters.Add(selectnewanchorcommand_sync_new_received_anchorParameter)
    End Sub
End Class

Open in new window


Thanks for your help.
0
 
LVL 1

Accepted Solution

by:
rkulp earned 0 total points
ID: 40378082
I solved the problem. I had referenced Microsoft.Synchronization.Data.SqlServerCe version 3.5.1 which matched the version of SqlServerCE used. When I changed it to version 2.0.0.0, the problem went away.
0
 
LVL 1

Author Closing Comment

by:rkulp
ID: 40388104
The expert asked for more information but did not respond, which is understandable since the lines referenced in the detail description really did not add anything. In desperation I found an old program that worked and matched every reference.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now