Page 1
Page 2
Page 3
Page 4
Page 5
Page 6
Page 7
Appendix B contains the tables we will be
using in this article. At this point, only pay attention to the
table named Contact. SQL Server generates the conflict_ContactManager_Contact
table when the publication is created.
The biggest difference you should notice is
the use of the uniqueidentifier data type instead of long integer
for the key of a row. SQL Replication uses Globally Unique
Identifiers (GUID) to guarantee unique ids across multiple
devices. Since the SQL Replication will be using these anyway,
we decided to use them as well. In code, you will treat the GUIDs
as strings.
Here we further discuss related configuration
issues and topics used.
| Issue |
Reference (SQL Server CE
Books Online) |
| Create the publication |
Replication\Implementing Replication\Configuring
SQL Server\Creating the Publication |
| Secure the publication |
Replication\Implementing Replication\Configuring
SQL Server\Securing the Publication |
| Create the snapshot folder |
This is done in create the
publication. SQL Server Relay, Synchronizing Data with SQL
Server CE\SQL Server CE Relay\Running SQL Server CE Relay
- Registering Relay with ActiveSync |
4. SQL Replication on PocketPC
Now that the system is configured, let's take
a look at the code.
- For sake of brevity, we omitted segments
of code not directly related to replication including:
- Verification that the database exists
- Save and retrieve functions
- Code displaying message boxes that are
used to interact with the client
- Deleting files.
To use the code examples, create the main
form used to edit contact information for our application (see
Appendix A). Add the code to the form from Appendix A. Add
the code from Appendix C and Appendix D as two modules. Appendix
E discusses the properties that are set for the replication object
used in Appendix D.
When the application is executed, we first
check for the existence of the database file. If this file is
not found, we need to create the initial database. The Create
button is displayed and all other controls are disabled. Once
the Create button is tapped, the application performs the following:
Private Sub cmdCreate_Click()
If (CreateDatabase) then
Call SynchronizeDatabase()
End If
End Sub
Listing 1
1. The CreateDatabase function
performs the following:
a. Create the replication object.
b. Initialize the replication object.
c. Add a subscription to central database via the replication
object.
Public Function CreateDatabase() As Boolean
On Error Resume Next
Dim bRetVal As Boolean
Dim oReplication As SSCE.Replication
bRetVal = False
' Create the replication object
Set oReplication = CreateObject(gcsCLASS_REPLICATION)
' Initialize properties of the Replication Object
Call InitializeReplicationObject(oReplication)
' Create the new anonymous subscription
Call oReplication.AddSubscription(CREATE_DATABASE)
' Return false if errors occurred
bRetVal = (oReplication.ErrorRecords.Count = 0) _
And (Err.Number = 0)
Set oReplication = Nothing
CreateDatabase = bRetVal
End Function
Listing 2
2. The InitializeReplicationObject function
sets parameters for our system. Appendix E contains information
about the specifics of each property.
a. Internet properties.
b. Publisher properties.
c. Subscriber properties.
d. Distributor properties.
Public Sub InitializeReplicationObject(ByRef
_
oReplication As SSCE.Replication)
On Error Resume Next
'These properties could be placed in a registry
'setting as well.
'The constants are defined in modGlobal
'Set Internet properties
oReplication.InternetURL = gcsINTERNET_URL
oReplication.InternetLogin = gcsINTERNET_LOGIN
oReplication.InternetPassword = gcsINTERNET_PASSWORD
oReplication.InternetProxyServer = _
gcsINTERNET_PROXY_SERVER
' Set Publisher properties
oReplication.Publisher = gcsPUBLISHER
oReplication.PublisherDatabase = gcsPUBLISHER_DB
oReplication.Publication = gcsPUBLICATION
oReplication.PublisherSecurityMode = DB_AUTHENTICATION
oReplication.PublisherNetwork = DEFAULT_NETWORK
oReplication.PublisherLogin = gcsPUBLISHER_LOGIN
oReplication.PublisherPassword = gcsPUBLISHER_PASSWORD
' Set Subscriber properties
oReplication.SubscriberConnectionString = gcsSUBSCRIBER_CONNECTION_STRING_PREFIX
& _
gcsLOCAL_DATABASE_FILE
oReplication.Subscriber = gcsSUBSCRIBER
' Set Distributor properties
oReplication.Distributor = gcsDISTRIBUTOR
oReplication.DistributorLogin = gcsDISTRIBUTOR_LOGIN
oReplication.DistributorPassword = _
gcsDISTRIBUTOR_PASSWORD
oReplication.DistributorSecurityMode = _
DB_AUTHENTICATION
End Sub
Previous Page
Next Page