DEVBUZZ Homepage Using replication on a SQL Server Database
 
Web www.devbuzz.com
  HOME PAGE
  All Articles
  Advertise
  Consulting

 Development
  Discuss - Forums
  Still in the box?
  .Compact Framework
  Code Snippets
  SQL Server CE
  Database
  MS Resources
 Stores
  Developer Controls
  Pocket PC Hardware
  Pocket PC Software
  Pocket PC Books
  .NET CF Books
  Book Reviews
  SPB SW Discounts
  RESCO SW Discounts
 DEVBUZZ Info
  About Us
  Help
  Join our email list
  Links & Ratings
  Press & Comments
  Pocket PC version
  Software Reviews
  Hardware Reviews
 Authors
  Authors
  Article Guide
  Competitions
 Resources
  Developers
  Register
  Login

  SPB Discounts!
 Columnists
  Rick Winscot
 Past Blast
  Personal Media Ctr
  Gizmobility
  eVB Legacy
  Old news
  Hosted Software
  Wireless
  Newsletters
  Carl Davis
  Upton Au

 Pocket PC Registry
  Join the registry
  View current list
 Current Poll
Are you converting to .NET Compact Framework?
Yes, it has changed my life!
No, I'm sticking with eVB
.NET CF what's that`?

Current results
3431 votes so far
 Recent Forum Threads [goto forums]

Get Computername
read... (67 hits)


Great aid to development productivity
read... (82 hits)


ThreadingTimer sample code
read... (143 hits)


Multithreading with .NET CF
read... (194 hits)


Moving from eMbedded Visual Basic to Visual Basic .NET
read... (166 hits)


.NET Compact Framework 2.0 Service Pack 2
read... (226 hits)


Transfer Data from SQL Server 2000 to SQL Server Compact Edition
read... (298 hits)


This protocol version is not supported
read... (236 hits)


Converting Lowercase to uppercase wont work
read... (203 hits)


Direct access to MS SQL Server 2000
read... (374 hits)


Creating SDF file in Desktop
read... (513 hits)


Winsock in CF.NET
read... (316 hits)


Using Pocket Outlook to submit HTML page form with MAILTO action
read... (420 hits)


Missing file "System.Data.PocketPC.asmmeta.dll"
read... (268 hits)


HP iPAQ hw6915 Serial Port Issue
read... (309 hits)


Info on the recent forum changes
read... (341 hits)


SqlServer tools from Redgate
read... (383 hits)


Arrow keys and Hardware navigation button
read... (393 hits)


O2 XDA lls pin sync cable to comport
read... (322 hits)


Creating dynamic folders on Pocket PC OS
read... (299 hits)

Custom Windows Mobile software development.
LBS Challenge 2007
LBS Challenge Eight previous NAVTEQ Global LBS Challenge® participants have received venture capital funding and nine past LBS Challenge winners have launched commercial applications on major wireless carriers. Register your non-commercial LBS application in the 2007 NAVTEQ Global LBS Challenge in one of three regions: Americas, Europe-Middle East-Africa (EMEA) or Asia-Pacific(APAC). You could win a share of $2 million in prizes. This could be your year.
Dream. Develop. Win.

Development | .NET Compact Framework

Using replication on a SQL Server Database
Written by Pete Vickers  [author's bio]  [read 15060 times]
Edited by Derek

Download the code   .NET Compact Framework   

Page 1  Page 2  Page 3 

Introduction

Merge replication is ideally suited to portable devices because it allows data to be updated autonomously on the portable device and the server. The data can later be merged when the device is connected to an instance of SQL Server. Server CE synchronizes with SQL Server by establishing an HTTP connection to the SQL Server Publisher through Microsoft Internet Information Services (IIS).

First of all, it is necessary to set up your server for merge replication. There is an excellent MSDN article by Microsoft, ‘Step by Step: Program Microsoft SQL Server CE 2.0 Merge Replication Using .NET Compact Framework’ at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnppcgen/html/eff_arch_sql_servr_ce_rep.asp

Use Part1, Part2 and Part3 of the above article. This will ensure that the ‘northwind’ database is set up for merge replication, and that IIS is also setup. Select all the tables for replication though, instead of just products.

To check that everything is set up correctly, run Internet Explorer, and in the address field enter http://(server_ip)/Northwind/sscesa20.dll as in Figure 7.

Figure 7 – Confirmation that IIS is set up correctly from the server

If the page displays as above, then you have set up correctly. If not, please check your settings.

With your device in the cradle, ensure that the connections are set to ‘My Work Network’. This can be verified by Start>Settings>Connections>Advanced>Select Networks, as in Figure 8.

Figure 8 – Network settings

When you have done this, start Pocket Internet Explorer, and in the address field enter http://(server_ip)/Northwind/sscesa20.dll as in Figure 9.

Figure 9 – Confirmation that IIS is set up correctly from the Pocket PC

If the page displays as above, then you have set up correctly. If not, please check your settings.

Accessing local SQL Server databases and Replication use the System.Data.SqlServerCe namespace. To add the references we need, in Visual Studio, click on Project > Add Reference, and add the following references
System.Data.SqlServerCe
System.Data.Common

In our code, we then have to import the namespaces.

Imports System.Net

Imports System.Data

Imports System.Data.SqlServerCe

Imports System.Io

Imports System.Drawing

Then we have to define the fields we need for replication and accessing the local database.

Private interneturl As String = "http://192.168.1.25/Northwind/sscesa20.dll" 'Replace with your IP

Private publisher_server As String = "delldesktop" 'Replace with the name of your server

Private publisher_database As String = "northwind"

Private publisher_secmode As SecurityType = SecurityType.NTAuthentication

Private publication As String = "northwind"

Private subscriber As String = Dns.GetHostName() 'This PPC

Private local_database As String = "\My Documents\northwind.sdf"

Private connection_string As String = "data source=" & local_database

Private strSql As String

Private SqlCmd As SqlCeCommand

Private sqlCeConn As SqlCeConnection

In the form load procedure, we open the local ‘northwind’ database, if it exists, using the function Open_Local_Database.

Private Sub Open_Local_Database()

If System.IO.File.Exists(local_database) Then

sqlCeConn = New SqlCeConnection

sqlCeConn.ConnectionString = connection_string

Try

sqlCeConn.Open()

Catch Ex As SqlServerCe.SqlCeException

DisplaySQLCeErrors(Ex, "Open " & connection_string)

End Try

End If

End Sub

When we first run, this database will not be present, but we are going to create it using replication. Our screen originally consists of 1 visible button, Connect & Sync. The code behind Connect & Sync sets up our replication parameters, creates the local database if it doesn’t already exist, and populates it.

Next Page 

Back to .NET Compact Framework | [Article Index]

 

Back to the top of the page.
Franson GPS tools for the Pocket PC Chris De Herrera's Windows CE Website Windows CE News & Information Source RESCO Software discounts
Copyright ©2000-2008 by DEVBUZZ.COM, Inc., TX. USA.