Skip to main content

Articles

News

Windows Mobile Developer Controls
Sapphire Soltuions

An overview of SQL Replication options

Written by Jarick Rager  [author's bio]  [read 89172 times]
Edited by Derek

Download the code

Page 1  Page 2  Page 3  Page 4  Page 5  Page 6  Page 7 

Listing 3

3. The SynchronizeDatabase function performs the following:
a. Create the replication object.
b. Initialize the replication object.
c. Call Initialize method of replication object.
d. Call Run method of replication object.
e. Call Terminate method of replication object.

'Synchronizes the CE database with a SQL Server 2000
'database.
'Returns true if synchronization is successful,
'otherwise false.
Public Function SynchronizeDatabase()
On Error Resume Next
Dim oReplication As SSCE.Replication
Dim bRetVal As Boolean
bRetVal = False
Set oReplication = CreateObject(gcsCLASS_REPLICATION)
' Initialize properties of the Replication Object
Call InitializeReplicationObject(oReplication)
' *** Replication Protocol ***
' Call Initialize
' Call Run
' Call Terminate
oReplication.Initialize
' Only continue if no errors occurred
If Not ((oReplication.ErrorRecords.Count > 0) Or _
(Err.Number <> 0)) Then
oReplication.Run
oReplication.Terminate
End If
' Only return true if operations did not have errors
bRetVal = (oReplication.ErrorRecords.Count = 0) And _
(Err.Number = 0)
Set oReplication = Nothing
SynchronizeDatabase = bRetVal
End Function

Listing 4

If the database file is found, the combo box is populated with the names of the contacts and the GUID is stored in a dynamic array. This was the biggest change we had to make when switching from the long integer to a GUID. Before the switch to GUID, we were using the ItemData property of the combo box to store the ID. Since ItemData is a number, we had to convert our code to store the GUIDs in an array.

When the client selects a contact from the combo box, we grab the GUID from the array by using the ListIndex property of the combo box. A SQL statement is used to retrieve the data from the database using the GUID in the WHERE clause. The values from the resulting records are displayed in the text fields.

The client makes changes as necessary and saves the information. Tap the Synchronize button to synchronize the PocketPC database with the laptop database. The SynchronizeDatabase function previously discussed is executed.

5. Infrared Transfer between PocketPC and Laptop

As we progressed in this proof-of-concept project, we encountered various technical hurdles. We work on a solution to these hurdles by building technical prototypes. Once the hurdle had been cleared, we then implemented the solution in our project.

Thus far, we have demonstrated capabilities to create and synchronize databases on a laptop and PocketPC. Synchronization occurs by running ActiveSync with the PocketPC placed in a USB cradle. Our next task was to implement infrared data transfer.

We began our investigation by launching ActiveSync, running our application, and synchronizing the data. Our application would need to launch ActiveSync programmatically. Fortunately, Microsoft had solved the technical issues as discussed in a Knowledge Base article, "HOWTO: Use the CreateProcess API from eMbedded Visual Basic" (KB Article Q265793).

In the KB Q265793 article, Microsoft use the command line parameter "/remote". We use the command line parameter "/ircomm". This seems to avoid the dialog boxes that usually come up asking the user to select the IR port. Beside that one difference, we put calls to StartActiveSync and StopActiveSync in the appropriate places and presto our technical prototype was complete!

6. Conflict Resolution between SQL Server 2000 and SQL Server CE

While synchronizing from multiple PocketPCs, conflicts will arise. The laptop application contains functionality to resolve those conflicts. In our model, we are directly querying the "conflict" tables. Andrea Fox wrote an article "Creating Merge Replication Custom Conflict Resolvers Using Visual Basic" which uses the Microsoft SQL Replication Conflict Resolver Library. Future endeavors will lead us to implementing this library in our model.

When the publication is created, SQL Server creates a series of five stored procedures with the following prefixes followed by a 32 alpha-numeric string for each table selected:

* sel_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
* sp_cft_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
* sp_ins_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
* sp_sel_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
* sp_upd_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

In addition, SQL Server generates several tables:

* MSdynamicsnapshotjobs
* MSdynamicsnapshotviews
* MSmerge_altsyncpartners
* MSmerge_contents
* MSmerge_delete_conflicts
* MSmerge_errorlineage
* MSmerge_genhistory
* MSmerge_replinfo
* MSmerge_tombstone
* MSrepl_identity_range
* sysmergearticles
* sysmergepublications
* sysmergeschemaarticles
* sysmergeschemachange
* sysmergesubscriptions
* sysmergesubsetfilters

Previous Page  Next Page