0
votes

I have an application that allows the entry of test results. The application needs to allow the user to enter data when offline and later sync to a remote database. The Microsoft Sync framework is used to accomplish this.

However, the tests carried out rely on data stored in many other databases, such as a list of tests cases and lists of devices. These lists are populated through the application and stored in a database. This is also carried out using the sync framework.

What I need to know is can I ensure that the data for the required lists remain in the locally cached database permanently so they can be retrieved when the application is offline. Hopefully then I can change the connection string at run time to ensure that queries are directed to the local database to retrieve the test cases and devices etc.

One solution is for the user to sync before they go off site to ensure they have the latest data but this will not always be possible.

EDIT

It seems to me that the once the sync is complete the local database is cleared and all changes that have been made are pushed to the remote database and deleted/removed from the local cached version. If the application is opened offline the local version cannot download the latest data from the remote database so there is no way to access the latest data.

I have tried to use the Microsoft.Synchronization.Data.ChangesSelectedEventArgs event to save the data locally every time there is a change but it doesn't seem to persist.

Private Sub LocalDeviceCacheServerSyncProvider_ChangesSelected(ByVal sender As Object, ByVal e As Microsoft.Synchronization.Data.ChangesSelectedEventArgs)

    If e.Context.DataSet.Tables.Contains("DeviceListTable") Then
        Dim dataTable = e.Context.DataSet.Tables("DeviceListTable")
        For j As Integer = 0 To dataTable.Rows.Count - 1
            Dim row As DataRow = dataTable.Rows(j)


            If row.RowState = DataRowState.Added Then

                dataTable.Rows.Add(dataTable.Rows(j))
            End If
        Next
    End If

End Sub

EDIT The problem was that when a remote server connection was unavailable an error was not thrown and the line of code that fills the datagridview never got executed. To get around this a try catch was used and the code to fill the datagrid is executed outside the try/ctach statement.

    Try
        Dim syncAgent As LocalCacheSyncAgent = New LocalCacheSyncAgent()
        Dim syncStats As Microsoft.Synchronization.Data.SyncStatistics = syncAgent.Synchronize()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

    Me.ReferenceListTableTableAdapter.Fill(Me.EMSCalResourcesDataSet.ReferenceListTable)
1

1 Answers

0
votes

Sync Framework doesn't delete rows that has been synchronized. the only time it will delete a row is if a delete of a row need to be synchronized. have you checked if your application is actually recreating your client database?