HOWTO: Perform Replication by Using SSCERelay and ActiveSync (304058)



The information in this article applies to:

  • Microsoft SQL Server 2000 Windows CE Edition

This article was previously published under Q304058

SUMMARY

This article describes how to perform Replication by using the SQL Server CE Relay (SSCERelay) executable, Sscerelay.exe, and ActiveSync.

MORE INFORMATION

The following steps describe how to use SSCERelay and ActiveSync to replicate data from the Customers table in the Northwind sample database to a Windows CE device by using Microsoft® SQL ServerT 2000 Windows® CE Edition (SQL Server CE) Merge Replication.
  1. Run SQL Server CE Relay manually. For example:
    1. On a Microsoft Windows 2000-based computer, open a command prompt.
    2. Change the directory to Program Files\Microsoft SQL Server CE\Relay.
    3. On the command line type the following command sscerelay /clientport 81 /servername <IIS server name> /serverport 80
      where <IIS server name> is the name of your Microsoft Internet Information Services (IIS) server.

      Press ENTER to run the command.

      NOTE: Optionally, you can specify the /register option at the end of the preceding command line.


  2. Create a new Microsoft eMbedded Visual Basic application.
  3. Add a command button to the default form, and then paste the following code in for the command:
    Private Sub Command1_Click()
    ' Declare the SQL Server CE ActiveX Replication Object Control.
       Dim ce As SSCE.Replication
    
       ' Create the Replication Object
       Set ce = CreateObject("SSCE.Replication.1.0")
    
       ' Set Replication properties
      ce.InternetURL = "http://myIISServerName/ssce/sscesa10.dll"
      ce.InternetProxyServer = "ppp_peer:81"
      ce.InternetLogin = "myInternetLogin"
      ce.InternetPassword = "myInternetPassword"
      ce.Publisher = "mySQLServer"
      ce.PublisherDatabase = "Northwind"
      ce.Publication = "myPublication"
      ce.PublisherLogin = "<useraccount>"
      ce.PublisherPassword = "<user_account_password>"
      ce.SubscriberConnectionString = "data source=\Local.sdf" 
      ce.Subscriber = "myCESub"
    
    ' Create the new anonymous subscription
      ce.AddSubscription (1)
    
      ' Perform the first synchronization to download the initial snapshot by
      ' calling the Initialize, Run and Terminate methods
      On Error Resume Next
      ce.Initialize
      If ce.ErrorRecords.Count > 0 Then
        ShowErrors ce.ErrorRecords
      Else
        On Error Resume Next
        ce.Run
        If ce.ErrorRecords.Count > 0 Then
          ShowErrors ce.ErrorRecords
        End If
        ce.Terminate
    
      End If
    
      Set ce = Nothing
    
    End Sub 
    
    
    Sub ShowErrors(ErrColl As SSCEErrors)
    
        'Initailize error variables to view error collection
        Dim ErrRec As Object    'SSCE.ErrorRecords
        Dim param As Object
        Dim strErr As String
            
        strErr = ""
    
        For Each ErrRec In ErrColl
             strErr = strErr & "Source: " & ErrRec.Source & vbCrLf
             strErr = strErr & "Number: " & Hex(ErrRec.Number) & vbCrLf
             strErr = strErr & "NativeError: " & ErrRec.NativeError & vbCrLf
             strErr = strErr & "Description: " & ErrRec.Description & vbCrLf
             For Each param In ErrRec.Params
                strErr = strErr & "Param" & " = " & param.param & vbCrLf
             Next param
             strErr = strErr & vbCrLf
        Next ErrRec
        
        MsgBox strErr, vbOKOnly
    
    End Sub
    					

NOTES

  • The InternetLogin and InternetPassword properties are required only if the SQL Server CE Server Agent is configured to use basic authentication. For anonymous authentication, comment out the following two lines because the default is no login:
    ce.InternetLogin = "myInternetLogin"
    ce.InternetPassword = "myInternetPassword"
    					
  • The example assumes that a Merge Publication for the Northwind sample database with the Customers table as an article belonging to the publication already exists, and that the Snapshot Agent has successfully generated the snapshot, and that the snapshot folder has been configured appropriately.
  • You must set the InternetProxyServer property to ppp_peer:81 (all lower case). If you use PPP_Peer:81 (all uppercase), the application may not work.
  • The example creates a subscription database named Local.sdf on the device.
  • Replace myIISServerName with the correct IIS computer name, and then specify the appropriate IIS authentication parameters.
  • Replace mySQLServer with the name of the computer that is running SQL Server that also contains the publication. Replace myPublication with the name of the merge publication. Replace the PublisherLogin and PublisherPassword properties with the correct values. The example assumes that you use SQL Server authentication, and that the Publisher and Distributor are on the same computer.
  • Replace myCESub with the name of the Windows CE device (optional).
  • From the computer that hosts SSCERelay, make sure that you can obtain the following Web site by using a Web browser: The word Body should appear if the connection is successful. If you cannot get this to work, you need to troubleshoot the IIS connectivity before you proceed with SQL Server CE Replication.
  • The URL that is used in the code assumes that the IIS virtual directory name is ssce. Replace ssce with the correct name if this is not the case.
  • Add references. For example: From the Project menu, click References, and then add references to the following:

    • Microsoft CE ADO Control 3.1
    • Microsoft CE ADO ext. 3.1 for DDL
    • Microsoft CE SQL Server Control 1.0

REFERENCES

SQL Server CE Books Online; topic: "Replication Programming"

Modification Type:MinorLast Reviewed:7/12/2004
Keywords:kbhowto KB304058