Enterprise Data Access with the Microsoft .NET Compact Framework

Microsoft's .NET Compact Framework provides Pocket PC developers with the tools needed to create robust applications, and offers several options for accessing and storing data from your enterprise database. This article will examine the most popular of these options, and is intended to be an overview of the subject for anyone contemplating using Pocket PCs in an enterprise setting.

The .NET framework is a platform which speeds development by giving developers access to a library of tested Classes and Functions, which they can use and re-use in their applications. Besides providing this "pre-built code," it also manages the code the developer writes by handling low-level functions such as memory allocation and disposal. The .NET Compact Framework (.NET CF) is a subset of the .NET framework, and is designed to run on Windows CE devices like the Pocket PC.

Before examining how to access your enterprise database, let's first discuss how data is stored on the device once it's been received. An understanding of storage options may help in choosing an access method, and give an appreciation of how .NET offers an end-to-end solution.

Intermittent Access

The reality of building applications for wireless or mobile devices is that access to your network or to the Internet is often intermittent. You may have some control over your environment and wireless networks in say, a factory or restaurant setting, but more often you are accessing data over the Internet, and then not continuously.

Retrieving and updating data may only occur at the start and end of a shift, in which case wireless functionality is not required. Regardless of your needs, a robust application should be able to store the data locally, use and manipulate it, and send changes (updates, inserts, deletions) back to the data source when a connection is available.

This introduces issues related to moving large amounts of data, and update conflicts, i.e. when several clients (Pocket PC applications) retrieve and modify the same data. In this conflict situation, it becomes a race back to the database, where the slowest user actually wins, and overwrites the faster user! Depending on your business this may not be an issue, but it's something to consider when analyzing your business requirements.

Central to the .NET framework is the idea of being disconnected from the central database and still being data-driven. Its central data object is the Dataset, which is like an in-memory representation of a simple database, complete with tables (called Datatables, containing rows and columns), relations (to create parent-child relationships between Datatables) and constraints (unique keys and foreign keys). The Datatable even has associated events, allowing you to control when the data in columns and rows changes in order to perform validation, enforce business rules, etc.

Mobile device constraints

Pocket PC development is much more constrained by limited memory and processing power than development for desktop computers. Constantly accessing data from a database adds the overhead of connecting, querying and retrieving the data each time. The Dataset allows you to store data in memory, with a powerful system for manipulating it. Changes to rows and columns in a Datatable are tracked, and you can use a DataAdapter object to retrieve the Dataset and, later, to automatically send the changes back to the database from which the data came. Once data is in the Dataset, you can easily bind it to .NET CF controls on the screen like the DataGrid. The point is that Microsoft has built its data model around the Dataset and the Datatable, and this is particularly useful to Pocket PC developers because of limited device resources.

Of course the Dataset is still in-memory data storage, and it should be saved elsewhere, i.e. the database from which it came. Otherwise, if the device does a soft reset, all data is lost. The Dataset is closely linked to standard XML, so you can easily load XML documents into a Dataset, and also save the contents of the Dataset to an XML file. So if you're not storing much data on the device, this may be an option.

SQL Server CE

 

Syndicate content