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 15146 times]
Edited by Derek

Download the code   .NET Compact Framework   

Page 1  Page 2  Page 3 

Figure 10 – Basic screen layout

First of all we set up our replication parameters.

Dim replicator As New SqlCeReplication

replicator.InternetUrl = interneturl

replicator.Publisher = publisher_server

replicator.PublisherDatabase = publisher_database

replicator.PublisherSecurityMode = publisher_secmode

replicator.Publication = publication

replicator.Subscriber = subscriber

replicator.SubscriberConnectionString = connection_string

Table 2 explains the settings for replication.

Table 2 – Replication parameters

Name

Description

InternetURL

SQL Server CE communicates with a SQL Server Agent (sscesa20.dll) running on the desktop computer by means of HTTP. IIS on the desktop computer has been configured to accept SQL Server CE requests and forward them to SQL Server by using the SQL Server Agent. The InternetURL property specifies the URL that has been configured for this purpose. In this example, the value is http://192.168.1.25 /Northwind/sscesa20.dll. You will need to replace 192.168.1.25 with the IP address of your server running IIS. Refer to Figures 7 and 9 for verification.

Publisher

The Publisher property identifies the instance of SQL Server publishing the publication in the form machineName\SQLServerInstanceName. In this example, the value is delldesktop.

PublisherDatabase

The PublisherDatabase is the Sql Server database we are using for Replication. In this example, it is Northwind

PublisherSecurityMode

The PublisherSecurityMode determines whether the subscriber application will use NT authentication (as in our sample), or PublisherLogin and PublisherPassword entries e.g. ‘sa’ and ‘admin’.

Publication

This identifies the subscribing device or computer.

Subscriber

This identifies the subscribing device or computer. This example uses DNS.Gethostname() to send the name of the device.

SubscriberConnectionString

This specifies the connection string for the local ‘northwind’ database, and is used both in replication, and in accessing the local database.

Next we attempt to connect to the IIS system, and create our local copy of ‘northwind’, by using AddSubscription

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

Try

replicator.AddSubscription(AddOption.CreateDatabase)

Catch ex As Exception

Cursor.Current = Cursors.Default

DisplaySQLCeErrors(ex, "Add")

End Try

End If

After we have created the database, we then attempt to populate it with the data from our publication (our ‘northwind’ SQL Server database).

Try

replicator.Synchronize()

Cursor.Current = Cursors.Default

MessageBox.Show("Database synched with Server", "Finished")

Open_Local_Database()

Refresh_Grid()

Catch ex As Exception

Cursor.Current = Cursors.Default

DisplaySQLCeErrors(ex, "Synch")

End Try

If this is successful, we display a message, as shown in Figure 11, otherwise we display the error collection, in the same way we did in the SQLCLIEN sample.

Figure 11 – Successful creation and replication.

We then open the local database, and display the regions in a grid control as show in figure 12.

Figure 12 – Records displayed from local database after replication.

Our application so far has connected to our IIS server, created a local database, and populated it. We will now move on to adding records to our local database, and replicating these back to our SQL Server. The code behind the Add Region button, will bring up a data-entry form, allowing us to enter a new region and description. Our data entry form will also do some validation, to ensure the fields are filled in correctly, and we are not trying to add a duplicate entry.

strSql = "Insert into region (regionid,regiondescription) values ("

strSql += txtID.Text & ",'" & txtRegion.Text & "')"

SqlCmd = New SqlCeCommand

SqlCmd = sqlCeConn.CreateCommand

SqlCmd.CommandText = strSql

Try

SqlCmd.ExecuteNonQuery()

SqlCmd = Nothing

Catch ex As SqlCeException

DisplaySQLCeErrors(ex, strSql)

End Try

Previous Page  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.