A call to PInvoke function error RRS feed

  • Question

  • I am getting the error "A call to PInvoke function " when I use the following code in my routine "Dim SyncStatistics As SyncStatistics = SyncAgent.Synchronize()".  When I investigate the properties everything looks setup okay.  I am testing synchronization services for its viability for a large project using a sample app that I threw together.  This code, the client and server databases sit on on box.  The demo app is written in vb.net.  Here is the code for the synchronize button:



    Private Sub btnSynchronize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSynchronize.Click

    '1. Instantiate the SyncAgent

    Dim SyncAgent As New SyncAgent()

    '2. Instantiate a client synchronization provider

    Dim clientsyncProvider As New SqlCeClientSyncProvider(ClientPOHeaderTableAdapter.Connection.ConnectionString)

    SyncAgent.ClientSyncProvider = clientsyncProvider

    '3. Instantiate a server synchronization provider

    Dim serversyncProvider As New DbServerSyncProvider()

    SyncAgent.ServerSyncProvider = serversyncProvider

    '4. Add the POHeader table: Bidirectional synchronization and that an existing table

    ' should be dropped.

    Dim poheaderSyncTable As New SyncTable("POHeader")

    poheaderSyncTable.CreationOption = TableCreationOption.DropExistingOrCreateNewTable

    poheaderSyncTable.SyncDirection = SyncDirection.Bidirectional



    '5. Create a command to retrieve a new anchor value from the server.

    ' SyncSession.SyncNewReceivedAnchor is a string constant;

    ' You could also use @sync_new_received_anchor directly in queries.

    Dim selectNewAnchorCommand As New SqlCommand()

    Dim newAnchorVariable As String = "@" + SyncSession.SyncNewReceivedAnchor

    With selectNewAnchorCommand

    .CommandText = "SELECT " + newAnchorVariable + " = @@DBTS"

    .Parameters.Add(newAnchorVariable, SqlDbType.Timestamp)

    .Parameters(newAnchorVariable).Direction = ParameterDirection.Output

    .Connection = Me.ServerPOHeaderTableAdapter.Connection

    End With

    serversyncProvider.SelectNewAnchorCommand = selectNewAnchorCommand

    '6. Create SyncAdapter for POHeader table, and define the commands to

    ' synchronize changes.

    Dim poheaderBuilder As New SqlSyncAdapterBuilder()

    With poheaderBuilder

    .Connection = Me.ServerPOHeaderTableAdapter.Connection

    .SyncDirection = SyncDirection.Bidirectional

    .TableName = "POHeader"

    .TombstoneTableName = .TableName + "_Tombstone"

    .CreationTrackingColumn = "InsertTimeStamp"

    .UpdateTrackingColumn = "UpdateTimeStamp"

    .DeletionTrackingColumn = "DeleteTimeStamp"

    End With

    Dim poheaderSyncAdapter As SyncAdapter = poheaderBuilder.ToSyncAdapter()

    poheaderSyncAdapter.TableName = "POHeader"

    'Add the SyncAdapter to the server synchronization provider


    'Start sync process.

    Dim SyncStatistics As SyncStatistics = SyncAgent.Synchronize()

    End Sub

    • Moved by Max Wang_1983 Friday, April 22, 2011 10:12 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Monday, August 27, 2007 1:35 PM