Windows Mobile 5.0 Data Access And Storage Webcast

1,367 views

Published on

Done as part of Webcast for Data Access with WM5.0 ...

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,367
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Windows Mobile 5.0 Data Access And Storage Webcast

    1. 1. Windows Mobile: Data Access and Storage Vinod Kumar M Technology Evangelist Microsoft India http://blogs.sqlxml.org/vinodkumar http://www.ExtremeExperts.com
    2. 2. Where We’re Going today What’s New In… <ul><li>Changes in SQL Mobile </li></ul><ul><li>Direct Data Management </li></ul><ul><li>Connectivity and Data Transfer </li></ul><ul><li>Tools and Productivity Enhancements </li></ul>
    3. 3. Changes in SQL Mobile
    4. 4. Changes in SQL Mobile Key new features <ul><li>Multi-user Support </li></ul><ul><ul><li>Can now access the same database from multiple programs simultaneously </li></ul></ul><ul><li>Improved Query Processor </li></ul><ul><ul><li>More optimized </li></ul></ul><ul><ul><li>No longer necessary to Compact to update statistics </li></ul></ul>
    5. 5. Changes in SQL Mobile Desktop Support <ul><li>SQL Mobile now available on the Desktop </li></ul><ul><ul><li>Databases can now be created on the desktop </li></ul></ul><ul><ul><li>Can now transfer a database using ActiveSync (no server engine required) </li></ul></ul><ul><ul><li>Can now administer database from desktop </li></ul></ul>
    6. 6. Changes in SQL Mobile Smartphone <ul><li>Smartphone now supports SQL Mobile </li></ul><ul><ul><li>Full featured support </li></ul></ul><ul><ul><li>Create, Query, Transactions… </li></ul></ul><ul><ul><li>Databinding </li></ul></ul><ul><ul><li>DataGrid </li></ul></ul>
    7. 7. Direct Data Management
    8. 8. Direct Data Management <ul><li>SqlCeResultset </li></ul><ul><ul><li>Updatable scrolling SQL Mobile cursor </li></ul></ul><ul><li>Dataset </li></ul><ul><ul><li>Improved parity with full .NET Framework </li></ul></ul><ul><ul><li>Easier to synchronize changes to/from full .NET Framework </li></ul></ul><ul><li>XML </li></ul><ul><ul><li>XML Serialization </li></ul></ul><ul><ul><li>XPath Support </li></ul></ul><ul><ul><li>XML Schema </li></ul></ul>
    9. 9. SqlCeResultSet <ul><li>SqlCeResultSet </li></ul><ul><ul><li>Provides direct connectivity to the SQL Server Mobile Edition database </li></ul></ul><ul><ul><li>Supports forward and backward scrolling </li></ul></ul><ul><ul><li>Supports updates </li></ul></ul><ul><ul><li>Supports databinding </li></ul></ul>
    10. 10. SqlCeResultSet Features vs. Performance <ul><li>Features comparable to DataSet commonly used features </li></ul><ul><ul><li>Scrolling </li></ul></ul><ul><ul><li>Updatability </li></ul></ul><ul><ul><li>Databinding </li></ul></ul><ul><li>Performance similar to SqlCeDataReader </li></ul><ul><ul><li>Direct db access </li></ul></ul><ul><ul><li>No in-memory data duplication </li></ul></ul>
    11. 11. SqlCeResultSet Compatability with SqlCeDataReader <ul><li>Inherits from SqlCeDataReader </li></ul><ul><ul><li>Provides strongly typed getters </li></ul></ul><ul><ul><ul><li>GetInt32(), GetString(), etc. </li></ul></ul></ul><ul><ul><li>Provides SqlCeDataReader forward Read() method </li></ul></ul><ul><ul><li>Fully compatible with existing SqlCeDataReader code you may have </li></ul></ul>
    12. 12. SqlCeResultSet Usage <ul><li>Created from SqlCeCommand ExecuteResultSet method </li></ul><ul><li>Specific behavior controlled by ResultSetOptions enumeration </li></ul>
    13. 13. SqlCeResultSet Usage (continued) string sql = &quot;Select ProductId, Desc, Qty, UnitPrice&quot;; SqlCeConnection conn = new SqlCeConnection(@&quot;Data Source = Orders.sdf&quot;); SqlCeCommand commmand = new SqlCeCommand(sql, conn); SqlCeResultSet rs = commmand.ExecuteResultSet(ResultSetOptions.None); while (rs.Read()) { // retrieve column values from the current record }
    14. 14. SqlCeResultSet Updatability <ul><li>Full Support for updatability </li></ul><ul><ul><li>Use ResultSetOptions.Updatable when executing the command </li></ul></ul><ul><ul><li>Use strongly typed Setters to modify columns </li></ul></ul><ul><ul><ul><li>SetInt32, SetString </li></ul></ul></ul><ul><ul><li>Call Update method to save record changes to the database </li></ul></ul>
    15. 15. SqlCeResultSet Updatability(continued) SqlCeResultSet rs = commmand.ExecuteResultSet(ResultSetOptions.Updatable); int idxProductId = rs.GetOrdinal(&quot;ProductId&quot;); int idxDesc = rs.GetOrdinal(&quot;Desc&quot;); int idxUnitPrice = rs.GetOrdinal(&quot;UnitPrice&quot;); 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 + &quot; - &quot; + desc); // Increase the price by 10% rs.SetDouble(idxUnitPrice, unitPrice * 1.1); // Apply record changes to db rs.Update(); }
    16. 16. SqlCeResultSet Scrolling Access <ul><li>Supports scrolling and direct record access </li></ul><ul><ul><li>Use ResultSetOptions.Scrollable when executing the command </li></ul></ul><ul><li>Provides Readxxx commands </li></ul><ul><ul><li>ReadFirsts, ReadLast </li></ul></ul><ul><ul><li>Read, ReadPrevious </li></ul></ul><ul><ul><li>ReadAbsolute </li></ul></ul><ul><ul><li>ReadRelative </li></ul></ul>
    17. 17. 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
    18. 18. SqlCeResultSet Databinding <ul><li>Create result set as normal </li></ul><ul><ul><li>All ResultSetOptions allowable </li></ul></ul><ul><ul><li>Should include ResultSetOptions.Scrollable </li></ul></ul><ul><li>Bind to the ResultSetView property of the result set </li></ul><ul><ul><ul><li>Provides same interfaces as DataView </li></ul></ul></ul><ul><ul><ul><ul><li>ITypedList, IBindingList, IList, ICollection, IEnumerable, IDisposable </li></ul></ul></ul></ul><ul><ul><ul><li>Can be used with any bindable controls </li></ul></ul></ul>
    19. 19. SqlCeResultSet Databinding (continued) SqlCeResultSet rs = commmand.ExecuteResultSet(ResultSetOptions.Scrollable); listBox1.DataSource = rs.ResultSetView; listBox1.DisplayMember = &quot;Desc&quot;; listBox1.ValueMember = &quot;ProductId&quot;; textBox1.DataBindings.Add(&quot;Text&quot;, rs, &quot;UnitPrice&quot;);
    20. 20. DataSet <ul><li>Several new methods added </li></ul><ul><ul><li>New methods improve parity with desktop </li></ul></ul><ul><ul><li>New methods make synchronizing changes much easier </li></ul></ul>
    21. 21. DataSet New Features/Methods <ul><li>Serialization methods now supported on a single table </li></ul><ul><li>DataSet.Copy method </li></ul><ul><li>DataSet.GetChanges method </li></ul><ul><li>DataSet.Merge </li></ul>
    22. 22. DataSet DataTable Serialization <ul><li>An individual data table can now be saved and restored </li></ul><ul><ul><li>WriteXml </li></ul></ul><ul><ul><li>ReadXml </li></ul></ul><ul><li>An individual data table can now be sent or received as a web service argument </li></ul><ul><ul><li>Simply pass as an argument </li></ul></ul>
    23. 23. DataSet DataTable Serialization private void DeptComplete(string deptName, DataSet ds) { DataTable dt = ds.Tables[&quot;DeptDetail&quot;]; dt.WriteXml(deptName + &quot;.xml&quot;); dt.Clear(); } private void DeptRestore(string deptName, DataSet ds) { DataTable dt = ds.Tables[&quot;DeptDetail&quot;]; dt.Clear(); dt.ReadXml(deptName + &quot;.xml&quot;); }
    24. 24. DataSet Copy Method <ul><li>Copy creates an exact duplicate </li></ul><ul><ul><li>Copy includes both data and schema </li></ul></ul><ul><ul><li>Useful for transferring a snapshot </li></ul></ul><ul><ul><ul><li>Snapshot can be sent in background </li></ul></ul></ul><ul><ul><ul><li>Application can still continue to function and modify original DataSet </li></ul></ul></ul>
    25. 25. 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
    26. 26. 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
    27. 27. DataSet Getting changes <ul><li>GetChanges method </li></ul><ul><ul><li>Retrieves changes since DataSet was loaded or AcceptChanges was called </li></ul></ul><ul><ul><li>Changes returned as a DataSet </li></ul></ul><ul><ul><li>The returned DataSet will generally be much smaller then original DataSet </li></ul></ul><ul><ul><li>Returned DataSet is optimized for merging </li></ul></ul>
    28. 28. DataSet Merging Changes <ul><li>Merge method </li></ul><ul><ul><li>Merges a DataSet into the current DataSet </li></ul></ul><ul><ul><li>Data is matched up based on primary key </li></ul></ul><ul><ul><li>Additions, deletions, modifications in the source DataSet are applied to the target </li></ul></ul>
    29. 29. 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
    30. 30. 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
    31. 31. XML Support <ul><li>Added more XML features </li></ul><ul><ul><li>Greater parity with the full framework </li></ul></ul><ul><ul><li>XML Serialization </li></ul></ul><ul><ul><li>XPath </li></ul></ul><ul><ul><li>XML Schema </li></ul></ul>
    32. 32. XML Serializer <ul><li>Classes can now be serialize/deserialized </li></ul><ul><ul><li>XmlSerializer class is the engine </li></ul></ul><ul><ul><li>Serialize saves class instance as XML </li></ul></ul><ul><ul><li>Deserialize restores the class instance </li></ul></ul><ul><li>Serialization Control </li></ul><ul><ul><li>Class must have default constructor </li></ul></ul><ul><ul><li>Attributes can control details </li></ul></ul><ul><ul><ul><li>XmlElement </li></ul></ul></ul><ul><ul><ul><li>XmlAttribute </li></ul></ul></ul>
    33. 33. XPath <ul><li>XPath now supported by XmlDocument </li></ul><ul><ul><li>Rich support for XPath queries </li></ul></ul><ul><ul><li>Notably simplifies XML processing </li></ul></ul><ul><li>Methods </li></ul><ul><ul><li>SelectNode </li></ul></ul><ul><ul><ul><li>Returns a single matching node </li></ul></ul></ul><ul><ul><li>SelectNodes </li></ul></ul><ul><ul><ul><li>Returns list of matching nodes </li></ul></ul></ul>
    34. 34. XmlSchema <ul><li>XmlSchema provides XML validation engine </li></ul><ul><ul><li>Eliminates the need to validate explicitly in code </li></ul></ul><ul><ul><li>Useful for verifying that a document appears as expected </li></ul></ul><ul><ul><li>Useful for verifying content to legacy web services </li></ul></ul><ul><ul><li>Can programmatically construct schemas </li></ul></ul>
    35. 35. Connectivity and Data Transfer
    36. 36. Connectivity and Data Transfer <ul><li>Detecting changes in connectivity </li></ul><ul><ul><li>Your application can now respond to changes in connectivity!! </li></ul></ul><ul><ul><li>Your application can the know type of connectivity (GPRS, Modem, ActiveSync…) </li></ul></ul><ul><li>MSMQ </li></ul><ul><ul><li>Reliable message delivery </li></ul></ul><ul><ul><li>Automatically handles connectivity </li></ul></ul>
    37. 37. Connectivity Detecting changes in connectivity <ul><li>Device connectivity is inconsistent </li></ul><ul><ul><li>Connectivity comes and goes </li></ul></ul><ul><ul><li>Type of connectivity may vary during application lifetime </li></ul></ul><ul><ul><ul><li>GPRS </li></ul></ul></ul><ul><ul><ul><li>Modem </li></ul></ul></ul><ul><ul><ul><li>ActiveSync </li></ul></ul></ul><ul><ul><ul><li>WiFi </li></ul></ul></ul><ul><ul><li>Applications must behave gracefully in the face of these changes </li></ul></ul>
    38. 38. Tools and Productivity Enhancements
    39. 39. Tools and Productivity Enhancements <ul><li>Visual Studio for Devices </li></ul><ul><ul><li>Manage device databases from your desktop!! </li></ul></ul><ul><ul><li>Copy SQL Mobile databases between your desktop and device </li></ul></ul><ul><ul><li>Generating typed Datasets </li></ul></ul>
    40. 40. Create and Manage <ul><li>Can now administer database from the desktop </li></ul><ul><ul><li>Create new database </li></ul></ul><ul><ul><li>Add tables </li></ul></ul><ul><ul><li>Define columns and indexes </li></ul></ul>
    41. 41. Create New Database
    42. 42. Creating New Table
    43. 43. Automatically adds to device
    44. 44. Typed DataSets <ul><li>.NET CF now supports typed DataSets </li></ul><ul><ul><li>Provides strongly typed table structure </li></ul></ul><ul><ul><li>Strongly typed properties of the column getters </li></ul></ul>
    45. 45. Summary <ul><li>Great enhancement to SQL Mobile </li></ul><ul><li>SqlCeResultSet provides updatable, scrollable cursor </li></ul><ul><li>DataSet provides new methods to make sync easier </li></ul><ul><li>Rich XML support </li></ul><ul><li>Can easily detect connectivity </li></ul><ul><li>Tools make device DB development as easy as server-based DB’s </li></ul>
    46. 46. <ul><li>For The Contest Questions and The Feedback Form, please log on to: </li></ul><ul><li>http://www.microsoft.com/India/ webcasts/eval/jan170430 </li></ul>
    47. 47. © 2006 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

    ×