Figure 1

Figure 1 Supported Windows CE-Powered Devices
Device
Windows CE Version
H/PC Professional
2.11
Palm-sized PC
2.11
Pocket PC
3.0
HPC 2000
3.0
Custom embedded device built using Platform Builder 3.0
3.0
Figure 2 Server Data Replication Support
SQL Server Version
Remote Data Access
Merge Replication
SQL Server 6.5


SQL Server 7.0


SQL Server 2000


Figure 3 Connections Through IIS

Figure 3 Connections Through IIS
Figure 4 Initial Synchronization
'  Declare and create the SQL Server CE Replication Object.
 Dim refRepl As SQL Server CE.Replication
 Set refRepl = CreateObject("SQL Server CE.Replication.1.0")

   '  Internet connection info .  That is, information
   '  needed for the "Windows CE-powered device to ISAPI DLL" connection.

   '  Internet location of the ISAPI DLL.
   '     (IIS server name / virtual directory name / DLL name)
   refRepl.InternetURL = "http://MyServer/Northwind/sscesa10.DLL"

   '  Internet user name and password
   refRepl.InternetLogin = ""
   refRepl.InternetPassword = ""
   
   '  Publisher (SQL Server) info .  That is, information
   '  needed for the "ISAPI DLL to SQL Server" connection.
   
   '  Name of the SQL Server where the published db resides.
   refRepl.Publisher "MyServer"
   
   '  Name of SQL Server db that has been published.
   refRepl.PublisherDatabase = "Nwind_SQLCE"
   
   '  Name of the publication.
   refRepl.Publication = "SQLCEReplDemo"
   
   '  Should DLL connect to SQL Server via Windows Authentication
   '     or via SQL Authentication.
   refRepl.PublisherSecurityMode = NT_AUTHENTICATION

   '  If SQL authentication then the SQL Server login/password
   '     must be specified.
   refRepl.PublisherLogin = ""
   refRepl.PublisherPassword = ""
   
   '  Subscriber (SQL Server CE) Info.  That is, 
   '     SQL Server CE database info.

   '  Connection string for SQL Server CE database
   refRepl.SubscriberConnectionString = "data source=\NorthwindRepl.sdf"
   
   '  Name of subscriber.  Does NOT need to be specified when
   '     setting up replication on the SQL server.  Instead,
   '     set up replication to use anonymous subscribers.
   refRepl.Subscriber = "SQLCESubscr"
   
   '  Create a new anonymous subscription.  The parameter
   '     indicates whether the SQL Server CE database already exists
   '     or should be created.
   refRepl.AddSubscription CREATE_DATABASE

   ' Perform the first synchronization to download the initial snapshot 
   '     by calling the Initialize, Run Terminate methods
   refRepl.Initialize
   refRepl.Run
   refRepl.Terminate
   Set refRepl = Nothing
Figure 5 Resynchronization
'  Declare the Replication Object.
   Dim refRepl As SSCE.Replication
   
   '  Create the Replication Object
   Set refRepl = CreateObject("SSCE.Replication.1.0")
 
   '  Internet connection info .  That is, information
   '  needed for the "Windows CE-powered device to ISAPI DLL" connection.
   refRepl.InternetURL = "http://MyServer/Northwind/sscesa10.dll"
   refRepl.InternetLogin = ""
   refRepl.InternetPassword = ""
   
   '  Publisher (SQL Server) info .  That is, information
   '  needed for the "ISAPI DLL to SQL Server" connection.
   refRepl.Publisher = "MyServer"
   refRepl.PublisherDatabase = "Nwind_SQLCE"
   refRepl.Publication = "SQLCEReplDemo"
   refRepl.PublisherSecurityMode = NT_AUTHENTICATION
   refRepl.PublisherLogin = ""
   refRepl.PublisherPassword = ""
   
   '  Subscriber (SQL Server CE) Info.  That is, SQL Server CE 
   '     database info.
   refRepl.SubscriberConnectionString = "data source=\NorthwindRepl.sdf"
   refRepl.Subscriber = "SQLCESubscr"
   
   ' Resynch the subscription by calling
   ' the Initialize, Run, Terminate methods
   refRepl.Initialize
   refRepl.Run
   refRepl.Terminate

Set refRepl = Nothing
Figure 7 Grant Access

Figure 7 Grant Access
Figure 10 Connect with Windows Authentication
Attribute VB_Name = "ReplAppSpecify"

'  Declare and create the SQL Server CE Replication Object.
   Dim refRepl As SSCE.Replication
   Set refRepl = CreateObject("SSCE.Replication.1.0")
            •••
'  Instruct sscesa10.dll to connect to SQL Server using
'     Windows Authentication.
   refRepl.PublisherSecurityMode = NT_AUTHENTICATION
            •••
'  Internet user name and password; that is, the
'     OS user that the dll should run as.
   refRepl.InternetLogin = "SFD00\ISAPIDLLTestUser"
   refRepl.InternetPassword = "password"
Figure 11 Open Connection
'  Create an RDA object
   Dim refRDA As SSCE.RemoteDataAccess
   Set refRDA = CreateObject("SSCE.RemoteDataAccess.1.0")

   '  Set the internet connection properties
   refRDA.InternetURL = "http://localhost/NorthWindRDA/sscesa10.dll"
   refRDA.InternetLogin = "SFD00\ISAPIDLLTestUser"
   refRDA.InternetPassword = "password"

   '  Submit the statement
   refRDA.SubmitSQL "INSERT INTO Region " & _
                        "VALUES(5, 'Central')", _
                     "Provider=SQLOLEDB.1;" & _
                        "Integrated Security=SSPI;" & _
                        "Persist Security Info=False;" & _
                        "Initial Catalog=Nwind_SQLCE;" & _
                        "Data Source=SFD00" _
   
   '  Cleanup
   Set refRDA = Nothing
Figure 12 Pull
'  Create an RDA object
   Dim refRDA As SSCE.RemoteDataAccess
   Set refRDA = CreateObject("SSCE.RemoteDataAccess.1.0")
   
   '  Set the internet connection properties
   refRDA.InternetURL = "http://localhost/NorthWindRDA/sscesa10.DLL"
   refRDA.InternetLogin = ""
   refRDA.InternetPassword = ""

   '  Set the SQL Server CE database connection string
   refRDA.LocalConnectionString = _
            "Provider=Microsoft.SQLSERVER.OLEDB.CE.1.0;" & _
            "Data Source=Northwind.sdf"
               
   '  Pull data from SQL Server to SQL Server CE
   '     The target table must not already exist.
   refRDA.Pull "SQLCETargetTable", _
               "SELECT CategoryID, CategoryName " & _
                 "FROM Categories", _
               "Provider=SQLOLEDB.1;" & _
                 "Integrated Security=SSPI;" & _
                 "Persist Security Info=False;" & _
                 "Initial Catalog=Northwind;" & _
                 "Data Source=SFD00", _
               TRACKINGON
               
   '  Cleanup
   Set refRDA = Nothing
Figure 13 Push
'  Create an RDA object
   Dim refRDA As SSCE.RemoteDataAccess
   Set refRDA = CreateObject("SSCE.RemoteDataAccess.1.0")
   
   '  Set the internet connection properties
   refRDA.InternetURL = "http://localhost/NorthWindRDA/sscesa10.DLL"
   refRDA.InternetLogin = ""
   refRDA.InternetPassword = ""

   '  Set the SQL Server CE database connection string
   refRDA.LocalConnectionString = _
            "Provider=Microsoft.SQLSERVER.OLEDB.CE.1.0;" & _
            "Data Source=Northwind.sdf"
               
   '  Push the changes back to SQL Server
   refRDA.Push "SQLCETargetTable", _
               "Provider=SQLOLEDB.1;" & _
                 "Integrated Security=SSPI;" & _
                 "Persist Security Info=False;" & _
                 "Initial Catalog=Northwind;" & _
                 "Data Source=SFD00"
               
   '  Cleanup
   Set refRDA = Nothing
Figure 14 Error Detection
Attribute VB_Name = "SQLCEErrorHandle"
   On Error Resume Next
   Set refRS = refConn.Execute("SELECT * FROM MyXTable")
   If Err.Number = 0 Then
      Do Until refRS.EOF
         Print refRS.Fields(0) & "  :  " & refRS.Fields(1)
         refRS.MoveNext
      Loop
   Else
      Dim refError As ADOCE.Error
      For Each refError In refConn.Errors
         MsgBox refError.Number & " : " & _
                refError.Source & " : " & _
                refError.Description
      Next refError
   End If
   On Error GoTo 0