Sales Orders Sample for Devices
New: 14 April 2006
This sample is the mobile device version of the
Sales Orders Sample for Merge Replication
. This sample highlights using Microsoft SQL Server 2005 Compact Edition (SQL Server Compact Edition) as a Subscriber in a merge replication topology for delivering data to mobile device users. It also demonstrates
the programmability features of replication in SQL Server Compact Edition. The sample is a Windows Forms-based application that uses standard Microsoft data access technologies and merge replication to enable a salesperson to maintain her own local data while
synchronizing periodically with the home office. The publication used by this sample is created when you install the
Sales Orders Sample for Merge Replication
. For more information about the replication scenario used in this sample, see
Sales Orders Sample Scenario
Before running this sample, make sure the following software is installed on the development computer:
- .NET Framework SDK 2.0 or Microsoft Visual Studio 2005 Service Pack 1 (SP1) or later versions. For more information, see
Installing the .NET Framework SDK.
- Microsoft SQL Server 2005 Compact Edition (SQL Server Compact Edition).
Microsoft ActiveSync 4.0 or later versions.
- SQL Server 2005 Service Pack 2 (SP2) or later versions.
- The SQL Server 2005 samples. These samples are included with SQL Server 2005 and are also available at the
SQL Server Developer Center. For more information, see
Installing Samples. You must also have either a mobile device or a mobile device emulator (included with Microsoft Visual Studio 2005) with at least 15 MB of free memory on which to deploy and run the sample.
To initialize the subscription and download sales order data to the device, you must have a SQL Server 2005 Publisher configured to run the
Sales Orders Sample for Merge Replication
The permissions required to configure and run the Sales Orders sample are based on replication security requirements, and are as follows:
- To run InstallSalesOrdersSample.bat at the Publisher, your Windows account must be a member of the
sysadmin fixed server role at the Publisher. This batch file configures replication, creates the AdvWorksSalesOrders publication, and generates the initial snapshot.
- To initialize the subscription and synchronize data with the Publisher, the Windows account used to connect to the Web server must meet the following requirements:
- Have a valid login at the Publisher associated with a user in the publication database.
- Have a valid login at the Distributor associated with a user in the distribution database (or the guest user).
- Be a member of the publication access list (PAL) for the AdvWorksSalesOrders publication.
Note: When you use an anonymous connection to the Web server, the IIS anonymous Windows account is used to connect to the Publisher.
- To connect to the Web server using Secure Sockets Layer (SSL) encryption, you must have a copy of the root certificate of the server certificate used to secure the Web server installed as a root certificate on the device. If the Web server is configured
to require client certificates, you must also have a valid certificate installed as a personal certificate on the device.
Building and Configuring the Sample
To configure the replication topology and build and deploy the sample project:
- At the Publisher, run the publication installation script from the Sales Orders sample.
- Build the Sales Orders sample and deploy the business logic handler assembly on the Web server.
- Run the Configure Web Synchronization wizard to configure the virtual directory.
- Build and deploy the sample to a device or device emulator using Visual Studio 2005.
To configure the Publisher, and build and deploy the sample project
- On a computer that is running SQL Server 2005, execute the installation script from the
Sales Orders Sample for Merge Replication to create the AdvWorksSalesOrders publication at the Publisher.
Note: The Sales Orders sample configuration script configures Web synchronization only for SQL Server 2005 and SQL Server Express Subscribers.
- At the command prompt, navigate to the SQL Server 2005 samples installation directory. The default is C:\Program Files\Microsoft SQL Server\90\Samples.
- Execute the following at a .NET Framework or Microsoft Visual Studio 2005 command prompt:
sn -k SampleKey.snk Note: You can skip this step if this key was previously created for use with another sample.
- Navigate to the installation location for the Sales Orders sample solution in Microsoft Visual C#. The default is C:\Program Files\Microsoft SQL Server\90\Samples\Replication\Merge\SalesOrders\CS.
- Open the SalesOrders.sln solution file in Visual Studio 2005.
- Build the project.
- Place a copy of the BusinessLogic.dll assembly in the C:\Program Files\Microsoft SQL Server\90\COM directory on the Web server.
- Run the Configure Web synchronization Wizard to create a virtual directory name "SalesOrdersMobile." For information about how to run this wizard, follow the steps in the
How To: Configure Connectivity with the Configure Web Synchronization Wizard topic in SQL Server Compact Edition Books Online.
Note: When client certificates are required to connect to the Web server, you must have a valid personal certificate installed on the device.
- If using an anonymous connection to the Web server, create a login at the Publisher for the Windows account used for anonymous access, create a user in the
AdventureWorks database for this login, and add this user to the PAL for the AdvWorksSalesOrders publication. For more information, see
How to: Manage Logins in the Publication Access List (SQL Server Management Studio).
- Navigate to the installation location for the Sales Orders Mobile device sample solution in Microsoft Visual C#. The default is C:\Program Files\Microsoft SQL Server\90\Samples\Replication\Merge\SalesOrdersMobile\CS.
- Open the SalesOrdersMobile.sln solution file in Visual Studio 2005.
- Connect the device or device emulator and start ActiveSync.
- Build and deploy the project to the device.
Running the Sample
To run the Sales Orders Mobile device sample and synchronize data
- Cradle the device and ensure that ActiveSync is running.
- To secure the connection to the Web server using SSL, export the root certificate of the server certificate used to secure the SalesOrdersMobile virtual directory (in DER encoded binary X.509 format), copy it to the device, and tap to install it as a root
certificate on the device. When client certificates are required to connect to the Web server, you must also have a valid personal certificate installed on the device.
Security Note: If you use Basic Authentication to connect to the Web server, you should use SSL to encrypt the connection to the Web server. This protects the Windows credentials.
- On the device, start Internet Explorer and browse to one of the following URLs:
- http://webserver/SalesOrdersMobile/sqlcesa30.dll?diag - when using anonymous access to the Web server.
- https://webserver/SalesOrdersMobile/sqlcesa30.dll?diag - when connecting to the Web server using SSL and specifying a Windows login and password to use for Basic Authentication.
- On the device or device emulator, start the SalesOrdersMobile program. When run for the first time, the program creates the SQL Server Compact Edition subscription database (\My Documents\AWMobile.sdf).
- On the Settings page, enter the name of the Publisher and the URL of the Web server in one of the following formats:
- http://webserver/SalesOrdersMobile/sqlcesa30.dll. This URL is used when the
Connect anonymously to server box is checked.
- https://webserver/SalesOrdersMobile/sqlcesa30.dll. This URL is used when the
Connect anonymously to server box is unchecked. You must also specify a Windows login and password in the
Windows login and Password fields, where these values are the credentials that correspond to a Windows login at the Publisher and Distributor.
- Tap Save to save these settings.
- On the Synchronize page, verify the value in the Hostname field, select
Full (recommended) for Sync type, and then tap Synchronize. The device connects to the specified Web server to create, initialize, and download subscription data for the application.
To update sales order data and synchronize with the Publisher
- With the subscription initialized, on the File menu, tap View Orders, and select a customer from the
- To update an existing order, tap on an existing order in the Orders table, then do one of the following:
- To update an existing item, double-tap an item in the Order Items grid, change the
Quantity value for the selected item, and then tap Save.
- To add a new item to the order, tap Add New, select the product from the
Category and Product lists, set the order quantity in the Quantity field, and then tap
- To delete an existing item from an order, select the item in the Order Items grid, and then tap
- Tap Synchronize from the Tools menu, select either Full (recommended) or
Upload only from the Sync type list, and then tap Synchronize. © 2007 Microsoft Corporation. All rights reserved.