Windows Mobile 5.0 Data Access And Storage Webcast - Presentation Transcript
Windows Mobile: Data Access and Storage Vinod Kumar M Technology Evangelist Microsoft India http://blogs.sqlxml.org/vinodkumar http://www.ExtremeExperts.com
Where We’re Going today What’s New In…
Changes in SQL Mobile
Direct Data Management
Connectivity and Data Transfer
Tools and Productivity Enhancements
Changes in SQL Mobile
Changes in SQL Mobile Key new features
Multi-user Support
Can now access the same database from multiple programs simultaneously
Improved Query Processor
More optimized
No longer necessary to Compact to update statistics
Changes in SQL Mobile Desktop Support
SQL Mobile now available on the Desktop
Databases can now be created on the desktop
Can now transfer a database using ActiveSync (no server engine required)
Can now administer database from desktop
Changes in SQL Mobile Smartphone
Smartphone now supports SQL Mobile
Full featured support
Create, Query, Transactions…
Databinding
DataGrid
Direct Data Management
Direct Data Management
SqlCeResultset
Updatable scrolling SQL Mobile cursor
Dataset
Improved parity with full .NET Framework
Easier to synchronize changes to/from full .NET Framework
XML
XML Serialization
XPath Support
XML Schema
SqlCeResultSet
SqlCeResultSet
Provides direct connectivity to the SQL Server Mobile Edition database
Supports forward and backward scrolling
Supports updates
Supports databinding
SqlCeResultSet Features vs. Performance
Features comparable to DataSet commonly used features
Scrolling
Updatability
Databinding
Performance similar to SqlCeDataReader
Direct db access
No in-memory data duplication
SqlCeResultSet Compatability with SqlCeDataReader
Inherits from SqlCeDataReader
Provides strongly typed getters
GetInt32(), GetString(), etc.
Provides SqlCeDataReader forward Read() method
Fully compatible with existing SqlCeDataReader code you may have
SqlCeResultSet Usage
Created from SqlCeCommand ExecuteResultSet method
Specific behavior controlled by ResultSetOptions enumeration
SqlCeResultSet Usage (continued) string sql = "Select ProductId, Desc, Qty, UnitPrice"; SqlCeConnection conn = new SqlCeConnection(@"Data Source = Orders.sdf"); SqlCeCommand commmand = new SqlCeCommand(sql, conn); SqlCeResultSet rs = commmand.ExecuteResultSet(ResultSetOptions.None); while (rs.Read()) { // retrieve column values from the current record }
SqlCeResultSet Updatability
Full Support for updatability
Use ResultSetOptions.Updatable when executing the command
Use strongly typed Setters to modify columns
SetInt32, SetString
Call Update method to save record changes to the database
SqlCeResultSet Updatability(continued) SqlCeResultSet rs = commmand.ExecuteResultSet(ResultSetOptions.Updatable); int idxProductId = rs.GetOrdinal("ProductId"); int idxDesc = rs.GetOrdinal("Desc"); int idxUnitPrice = rs.GetOrdinal("UnitPrice"); while (rs.Read()) { // Retrieve current values string productId = rs.GetString(idxProductId); string desc = rs.GetString(idxDesc); double unitPrice = rs.GetDouble(idxUnitPrice); // Prepend Product ID to the description rs.SetString(idxDesc, productId + " - " + desc); // Increase the price by 10% rs.SetDouble(idxUnitPrice, unitPrice * 1.1); // Apply record changes to db rs.Update(); }
SqlCeResultSet Scrolling Access
Supports scrolling and direct record access
Use ResultSetOptions.Scrollable when executing the command
Provides Readxxx commands
ReadFirsts, ReadLast
Read, ReadPrevious
ReadAbsolute
ReadRelative
SqlCeResultSet Scrolling Access (continued) SqlCeResultSet rs = commmand.ExecuteResultSet(ResultSetOptions.Scrollable | ResultSetOptions.Updatable ); // Read entire result backwards rs.ReadLast(); while(rs.ReadPrevious(); { // ... } // Absolute positioning rs.ReadAbsolute(10); // Read 10 records from beginning rs.ReadAbsolute(-10); // Read 10 records from end // Relative positioning rs.ReadRelative(5); // Read forward 5 records rs.ReadRelative(-5); // Read backward 5 records
SqlCeResultSet Databinding
Create result set as normal
All ResultSetOptions allowable
Should include ResultSetOptions.Scrollable
Bind to the ResultSetView property of the result set
Application can still continue to function and modify original DataSet
DataSet Copy Method (continued) [WebMethod] public void SaveSnapshot(DataSet ds) { WriteDataSetToDatabase(ds); } private void Upload(DataSet ds) { DataServerProxy wsProxy = new DataServerProxy(); wsProxy.SaveSnapshot(ds); } Target Web Service Device call – Too slow, user must wait for whole upload
DataSet Copy Method (continued) private void Upload(DataSet ds) { DataServerProxy wsProxy = new DataServerProxy(); wsProxy.BeginSaveSnapshot(ds, null, null); } private void Upload(DataSet ds) { DataServerProxy wsProxy = new DataServerProxy(); DataSet dsDupe = ds.Copy(); wsProxy.BeginSaveSnapshot(dsDupe, null, null); } Device call – Changes to data during upload will corrupt upload Device call – Send copy in background, this is safe
DataSet Getting changes
GetChanges method
Retrieves changes since DataSet was loaded or AcceptChanges was called
Changes returned as a DataSet
The returned DataSet will generally be much smaller then original DataSet
Returned DataSet is optimized for merging
DataSet Merging Changes
Merge method
Merges a DataSet into the current DataSet
Data is matched up based on primary key
Additions, deletions, modifications in the source DataSet are applied to the target
DataSet Retrieving Changes from server [WebMethod] public DataSet GetLatest(DateTime startingDate) { return RetrieveChangesFromDatabase(startingDate); } private void GetUpdates(DataSet currentDs, DateTime lastUpdate) { DataServerProxy wsProxy = new DataServerProxy(); DataSet changeDs = wsProxy.GetLatest(lastUpdate); currentDs.Merge(changeDs); } Web method on server Call to web method from device
DataSet Sending Changes to the server [WebMethod] public void StoreUpdates(DataSet changeDs) { ApplyChangesToDataBase(changeDs); } private void SendChanges(DataSet currentDs) { DataServerProxy wsProxy = new DataServerProxy(); DataSet changeDs = currentDs.GetChanges(); wsProxy.StoreUpdates(changeDs); } Web method on server Call to web method from device
XML Support
Added more XML features
Greater parity with the full framework
XML Serialization
XPath
XML Schema
XML Serializer
Classes can now be serialize/deserialized
XmlSerializer class is the engine
Serialize saves class instance as XML
Deserialize restores the class instance
Serialization Control
Class must have default constructor
Attributes can control details
XmlElement
XmlAttribute
XPath
XPath now supported by XmlDocument
Rich support for XPath queries
Notably simplifies XML processing
Methods
SelectNode
Returns a single matching node
SelectNodes
Returns list of matching nodes
XmlSchema
XmlSchema provides XML validation engine
Eliminates the need to validate explicitly in code
Useful for verifying that a document appears as expected
Useful for verifying content to legacy web services
Can programmatically construct schemas
Connectivity and Data Transfer
Connectivity and Data Transfer
Detecting changes in connectivity
Your application can now respond to changes in connectivity!!
Your application can the know type of connectivity (GPRS, Modem, ActiveSync…)
MSMQ
Reliable message delivery
Automatically handles connectivity
Connectivity Detecting changes in connectivity
Device connectivity is inconsistent
Connectivity comes and goes
Type of connectivity may vary during application lifetime
GPRS
Modem
ActiveSync
WiFi
Applications must behave gracefully in the face of these changes
Tools and Productivity Enhancements
Tools and Productivity Enhancements
Visual Studio for Devices
Manage device databases from your desktop!!
Copy SQL Mobile databases between your desktop and device
0 comments
Post a comment