Mobile Data with the Compact Framework Shawn Wildermuth Senior Consultant/Architect Magenic Technologies Shawn Wildermuth Senior Consultant/Architect Magenic.

Slides:



Advertisements
Similar presentations
17. Data Access ADO.Net Architecture New Features of ADO.NET
Advertisements

Programming with ADO.NET By Sam Nasr April 27, 2004 Programming with ADO.NET By Sam Nasr April 27, 2004.
DEV351 ADO.NET Performance Pablo Castro Program Manager – ADO.NET Team Microsoft Corporation.
 Steve Lasker Program Manager Microsoft Corporation blogs.msdn.com/SteveLasker PC40.
Developing Mobile Applications Tim Heuer Bert Solano
Chapter 10 ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a programming interface to access data in a database.
ADO. NET. What is “ADO.Net”? ADO.Net is a new object model for dealing with databases in.Net. Although some of the concepts are similar to the classical.
.NET Mobile Application Development Data in Distributed Systems Accessing Data with.NET.
Objective In this session we will discuss about : What is ADO. NET ?
The What, Why, and How... Nino Benvenuti MVP – Device Application Development
What’s new for Rich Clients? Martin Parry Developer & Platform Group Microsoft Ltd
Data Access with SQL Server 2005 Mobile Edition and the.NET Compact Framework v2.0 Scott Colestock.
Query Processing in Mobile Databases
MBL290: Building Mobile Applications with Microsoft® SQL Server™ CE and the Microsoft.NET Compact Framework Kevin Collins Microsoft Senior Program Manager.
Stored Procedures Dr. Ralph D. Westfall May, 2009.
Windows Mobile 5.0 Features & Functionality! Wim Verhaeghen - Erwin van Hunen -
ADO.NET Tips and Tricks How to get the most out of your data access…
ADO.NET – part II August 2004 [ Marmagna Desai]. CONTENTS ADO vs ADO.NET ADO.NET – Managed providers Connecting to Database SqlConnection Selecting Database.
CNUG Day of.NET: October 30th SQL Server 2005: A Developers Introduction Shawn Wildermuth Magenic Technologies, Inc.
DAT336 Connected vs Disconnected Data Access in ADO.NET Pablo Castro Program Manager – ADO.NET Team Microsoft Corporation.
ADO.NET A2 Teacher Up skilling LECTURE 3. What’s to come today? ADO.NET What is ADO.NET? ADO.NET Objects SqlConnection SqlCommand SqlDataReader DataSet.
CIS 375—Web App Dev II ASP.NET 10 Database 2. 2 Introduction to Server-Side Data Server-side data access is unique in that Web pages are basically ___________.
Needs for Accessing Database To make your web site more dynamic and maintainable, you can display information on your web pages that are retrieved from.
Databases and Data Access  Introduction to ADO.NET  ADO.NET objects  ADP.NET namespaces  Differences between ADO and ADO.NET.
.NET Data Access and Manipulation ADO.NET. Overview What is ADO.NET? Disconnected vs. connected data access models ADO.NET Architecture ADO.NET Core Objects.
.Net and Web Services Security CS795. Web Services A web application Does not have a user interface (as a traditional web application); instead, it exposes.
SQL Server 2005: The CLR Integration What Developers and DBAs need to know.
Database, SQL, and ADO.NET- Part 1 Session 11 Mata kuliah: M0874 – Programming II Tahun: 2010.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL ADO.Net Basics Ruwan Wijesinghe Trainer.
ASP.NET Rina Zviel-Girshin Lecture 5
Session 8: ADO.NET. Overview Overview of ADO.NET What is ADO.NET? Using Namespaces The ADO.NET Object Model What is a DataSet? Accessing Data with ADO.NET.
Module 7: Accessing Data by Using ADO.NET
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Introduction to ADO.NET ADO.NET - Lesson 01  Training time: 10 minutes  Author:
Windows Forms in Visual Studio 2005 Mike Pelton Systems Engineer Microsoft Ltd
Object Oriented Software Development 10. Persistent Storage.
Presented by Joseph J. Sarna Jr. JJS Systems, LLC
An Introduction to ADO.Net Marmagna Desai.NET Seminar, Fall-2003.
ADO.NET Tips and Tricks How to get the most out of your data access…
Marcus Perryman Microsoft
Database Farming For Improved Performance Presented By: Russell Yong Supervisor: Prof Wentworth.
MBL401.Net Compact Framework: Data Access Best Practices Paul Foster Mobile solutions architect.
Why ADO.NET Not your father’s Data Access.
SQL Server 2005 Implementation and Maintenance Chapter 12: Achieving High Availability Through Replication.
Extending the Enterprise using.NET CF and SQL CE Marcus Perryman Principal Consultant Microsoft.
Mobile Applications and SQL Server Mobile v3.0 (Laguna) Kevin Collins Senior Program Manager Microsoft Corporation.
Building Data-Centric Smart Client Applications Rajiv Sodhi Microsoft India.
Why ADO.NET Not your father’s Data Access.
Module 3: Working with Local Data. Overview Using DataSets Using XML Using SQL Server CE.
The Mobile Architect Morgan Skinner. Agenda Common Patterns and Designs Common Patterns and Designs Architecting Mobile Applications Architecting Mobile.
DataSets Demystified. Who I am Shawn Wildermuth Senior Consultant with Magenic Technologies ( C# MVP INETA.
1 Database Programming with ADO.NET Kashef Mughal.
C# .NET Software Development
SVR201 SQL Server 2005 Mobile Edition: The Evolution Of SQL Server CE Scott Smith Program Manager Visual Studio for Devices Microsoft Corporation.
Log Shipping, Mirroring, Replication and Clustering Which should I use? That depends on a few questions we must ask the user. We will go over these questions.
Exploring Networked Data and Data Stores Lesson 3.
Data Access. ADO.NET ADO.NET is the primary library for building database solutions within the.NET Framework. ADO.NET does not replace ADO. ADO and OLEDB.
ADO .NET from. ADO .NET from “ADO .Net” Evolution/History of ADO.NET MICROSOFT .NET “ADO .Net” Evolution/History of ADO.NET History: Most applications.
.NET Data Access and Manipulation
 ADO.NET is an object-oriented set of libraries that allows you to interact with data sources  Commonly, the data source is a database, but it could.
Developing Mobile Applications
Introduction to ADO.NET
Introduction to Database Processing with ADO.NET
6/12/2018 5:09 AM © 2004 Microsoft Corporation. All rights reserved.
Mobile Application Development 2005 By Sam Nasr July 25, 2006
VB.NET Using Database.
An Introduction to Entity Framework
Chapter 10 ADO.
Visual Studio + SQL Server Is Better
Introduction to Database Programming through ADO. NET
Getting Data Where and When You Want it with SQL Server 2005
Presentation transcript:

Mobile Data with the Compact Framework Shawn Wildermuth Senior Consultant/Architect Magenic Technologies Shawn Wildermuth Senior Consultant/Architect Magenic Technologies

Who I Am Shawn Wildermuth C# MVP INETA Speaker Book Author – “Pragmatic ADO.NET” Editor of This Presentation can be found at: – Shawn Wildermuth C# MVP INETA Speaker Book Author – “Pragmatic ADO.NET” Editor of This Presentation can be found at: –

Agenda How Mobile Data is Different Deciding on a Solution Limitations of the Compact Framework Using SqlClient Using SQL Server CE Using Web Services Data Binding on the Compact Framework SQL Server CE 2005 (Yukon) How Mobile Data is Different Deciding on a Solution Limitations of the Compact Framework Using SqlClient Using SQL Server CE Using Web Services Data Binding on the Compact Framework SQL Server CE 2005 (Yukon)

How Mobile Data is Different The form factor is small – Not much screen real estate – Not much memory room Needs to work disconnected – Very few Mobile devices are always connected – Smaller bandwidth usually when connected The form factor is small – Not much screen real estate – Not much memory room Needs to work disconnected – Very few Mobile devices are always connected – Smaller bandwidth usually when connected

Deciding on a Solution Is a Smart Client the right solution? – How much data manipulation is needed? – Is offline support needed? – Does state need to be shared with servers If Smart Client, which Data Access? – Options include:  SQL Server Data Access  SQL Server CE Data Access  Web Services Is a Smart Client the right solution? – How much data manipulation is needed? – Is offline support needed? – Does state need to be shared with servers If Smart Client, which Data Access? – Options include:  SQL Server Data Access  SQL Server CE Data Access  Web Services

Limitations of the CF System.Data – DataSets work fine – Typed DataSets don’t – No Design-time Support System.Xml – No XML Serialization Support – OpenNETCF’s Xml Serialization isn’t Complete System.Runtime.Serialization – No SOAP or Binary Formatters System.Data – DataSets work fine – Typed DataSets don’t – No Design-time Support System.Xml – No XML Serialization Support – OpenNETCF’s Xml Serialization isn’t Complete System.Runtime.Serialization – No SOAP or Binary Formatters

Limitations of the CF (2) SqlClient – Only on CE and Pocket PC (no SmartPhone) – Requires Connectivity SQL CE – Only on CE and Pocket PC (no SmartPhone) Web Services – Support on all platforms – Somewhat slower (not compressed like above) SqlClient – Only on CE and Pocket PC (no SmartPhone) – Requires Connectivity SQL CE – Only on CE and Pocket PC (no SmartPhone) Web Services – Support on all platforms – Somewhat slower (not compressed like above)

Limitations of the CF (3) DataSet is limited – Merge() and GetChanges() are missing – Deal with changes row-by-row DataSet is limited – Merge() and GetChanges() are missing – Deal with changes row-by-row

SQL Client Data Access Remarkable similar to SqlClient in Full Fx – Full Set of Adapter Functionality Supported – Connection Strings are to real SQL Server Remarkable similar to SqlClient in Full Fx – Full Set of Adapter Functionality Supported – Connection Strings are to real SQL Server // Create the connection and command SqlConnection conn = new SqlConnection("..."); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM Customers"; // Create a DataSet to put our results in DataSet ds = new DataSet(); // Create the adapter SqlDataAdapter da = new SqlDataAdapter(cmd); // Fill it da.Fill(ds, "Customers");

SQL Client Data Access (2) Readers are also supported – Same caveats apply to Mobile Apps – Connected apps are hard on low bandwidth Readers are also supported – Same caveats apply to Mobile Apps – Connected apps are hard on low bandwidth // Create the connection and command SqlConnection conn = new SqlConnection("..."); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM Customers"; // Use a Reader try { conn.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { string name = rdr["CompanyName"].ToString(); } finally { conn.Close(); }

SQL Server CECLIENT SERVER QP/Cursor Engine/ES Storage Engine / Repl Tracking SQL CE Edition v2.0 OLEDB OLEDB OLEDB CE CLR /.NET CF SQL Server CE Data Provider ADO.NET VS.NET (VB.NET, C#).NET CF / Managed Stack IIS Server Agent: Replication and Remote Data Access HTTP b, CDPD, GSM, CDMA, TDMA, etc. Occasionally Connected Data Provider Client Agent: Replication andRDA

SQL Server CE (2) Two Methodologies – Remote Data Access  Local Database  Push and Pull Access from SQL Server  Optional Change Tracking – Merge Replication  Use Replication Engine to Sync Changes  Use Subscription model instead of RDA Model  Allows vertical and horizontal partitioning Two Methodologies – Remote Data Access  Local Database  Push and Pull Access from SQL Server  Optional Change Tracking – Merge Replication  Use Replication Engine to Sync Changes  Use Subscription model instead of RDA Model  Allows vertical and horizontal partitioning

Setting up SQL Server CE - RDA Integrates with IIS – ISAPI Application to access remote data  E.g. /sqlce/sscesa20.dll  Compresses results across the wire – SqlCeRemoteDataAccess  Takes an URL to the ISAPI App;  and Connection String to database on mobile device Integrates with IIS – ISAPI Application to access remote data  E.g. /sqlce/sscesa20.dll  Compresses results across the wire – SqlCeRemoteDataAccess  Takes an URL to the ISAPI App;  and Connection String to database on mobile device SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess(" "Data Source=northwind.sdf");

SQL Server CE - RDA Pulling Data to Mobile Device – Creation of the local DB with ad-hoc queries – Uses an OLEDB Connection String to connect – Pull to bring data from remote db to mobile db – Can include tracking information for updating Pulling Data to Mobile Device – Creation of the local DB with ad-hoc queries – Uses an OLEDB Connection String to connect – Pull to bring data from remote db to mobile db – Can include tracking information for updating string rdaOleDbConnectString = "Provider=sqloledb;Data Source=shawnw-lptd;" + "Initial Catalog=Northwind;User Id=Sample;Password=ADONET"; rda.Pull("Customers", "SELECT * FROM Customers", rdaOleDbConnectString, RdaTrackOption.TrackingOnWithIndexes); rda.Pull("Products", "SELECT * FROM Products", rdaOleDbConnectString, RdaTrackOption.TrackingOnWithIndexes); rda.Pull("Orders", "SELECT * FROM Orders", rdaOleDbConnectString, RdaTrackOption.TrackingOnWithIndexes); rda.Pull("OrderDetails", "SELECT * FROM OrderDetails", rdaOleDbConnectString, RdaTrackOption.TrackingOnWithIndexes);

SQL Server CE – RDA (2) Uses local database storage – Use of SqlCe* classes to access data normally – Supports full suite of classes Uses local database storage – Use of SqlCe* classes to access data normally – Supports full suite of classes // Create the connection and command SqlCeConnection conn = new SqlCeConnection("..."); SqlCeCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM Customers"; // Create a DataSet to put our results in DataSet ds = new DataSet(); // Create the adapter SqlCeDataAdapter da = new SqlCeDataAdapter(cmd); // Fill it da.Fill(ds, "Customers");

SQL Server CE – RDA (3) Pushing data back – Pushes changed rows back to remote DB – Only if tracking is enabled – Batching does all rows in single Tx Pushing data back – Pushes changed rows back to remote DB – Only if tracking is enabled – Batching does all rows in single Tx rda.Push("Customers", rdaOleDbConnectString, RdaBatchOption.BatchingOn); rda.Push("Products", rdaOleDbConnectString, RdaBatchOption.BatchingOn); rda.Push("Orders", rdaOleDbConnectString, RdaBatchOption.BatchingOn); rda.Push("OrderDetails", rdaOleDbConnectString, RdaBatchOption.BatchingOn);

SQL Server CE – Merge Replication Retrieves Data with Replication – Fills the local DB from replication subscription – Like RDA, uses ISAPI Application – And local database connection for local cache Retrieves Data with Replication – Fills the local DB from replication subscription – Like RDA, uses ISAPI Application – And local database connection for local cache SqlCeReplication repl = new SqlCeReplication(); repl.InternetUrl = " repl.Publisher = "SHAWNW-LPTD"; repl.PublisherDatabase = "Northwind"; repl.PublisherLogin = "sample"; repl.PublisherPassword = "ADONET"; repl.Publication = "Northwind"; repl.Subscriber = "OrderTaker"; repl.SubscriberConnectionString = "Data Source=northwind.sdf"; // Create the Local SSCE Database subscription repl.AddSubscription(AddOption.CreateDatabase); // Synchronize to the SQL Server 2000 to populate the Subscription repl.Synchronize();

SQL Server CE – Merge Replication (2) Local access is identical to RDA – Uses same local database – And same data access classes Local access is identical to RDA – Uses same local database – And same data access classes // Create the connection and command SqlCeConnection conn = new SqlCeConnection("..."); SqlCeCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM Customers"; // Create a DataSet to put our results in DataSet ds = new DataSet(); // Create the adapter SqlCeDataAdapter da = new SqlCeDataAdapter(cmd); // Fill it da.Fill(ds, "Customers");

SQL Server CE – Merge Replication (3) Merges back to remote db with Replication – Uses same replication object as filled local db – Synchronize uses Merge Replication Merges back to remote db with Replication – Uses same replication object as filled local db – Synchronize uses Merge Replication SqlCeReplication repl = new SqlCeReplication(); //... // Synchronize to the SQL Server 2000 // to populate the Subscription repl.Synchronize();

SQL Server CE - Caveats Several SQL Constructs don’t work – Batch queries – Object names with spaces (cannot use delimiters)  SELECT * FROM [Order Details] – Queries are run with unchangable defaults  QUOTED_IDENTIFIER_ON, ANSI_NULLS_ON, ANSI_PADDING_ON, ANSI_NULL_DFLT_ON_ON, CONCAT_NULL_YIELDS_NULL_ON Several SQL Constructs don’t work – Batch queries – Object names with spaces (cannot use delimiters)  SELECT * FROM [Order Details] – Queries are run with unchangable defaults  QUOTED_IDENTIFIER_ON, ANSI_NULLS_ON, ANSI_PADDING_ON, ANSI_NULL_DFLT_ON_ON, CONCAT_NULL_YIELDS_NULL_ON

Web Services SOAP Based Data Access – Only real data access on SmartPhones – Doesn’t require local connectivity – Use WriteSchema to pass whole structure of DS – Can use DataSets for updates SOAP Based Data Access – Only real data access on SmartPhones – Doesn’t require local connectivity – Use WriteSchema to pass whole structure of DS – Can use DataSets for updates [WebMethod] public XmlDocument Products() { //... // Using WriteSchema to make sure the entire // structure is included on client side MemoryStream strm = new MemoryStream(); ds.WriteXml(strm, XmlWriteMode.WriteSchema); strm.Position = 0; XmlDocument doc = new XmlDocument(); doc.Load(strm); return doc; }

Web Services (2) The Client consumes it normally – Can use DataSets on the client for cache – Use ReadSchema to fill in DS Structure The Client consumes it normally – Can use DataSets on the client for cache – Use ReadSchema to fill in DS Structure // Create the service GetPhoneDataService theSvc = new GetPhoneDataService(); // Load the data through the Web Service XmlDocument doc = theSvc.Products(); // NOTE: Can't use a Typed DataSet Here // Make it into a DataSet DataSet ds = new DataSet(); XmlNodeReader rdr = new XmlNodeReader(node); ds.ReadXml(rdr, XmlReadMode.ReadSchema); // Must use AcceptChanges // (ReadXml makes rows new) ds.AcceptChanges();

Web Services (3) Can store DataSet locally for cache – This allows for the device to be disconnected – Saving the data locally includes the changes – Use DiffGrams to preserve the changes Can store DataSet locally for cache – This allows for the device to be disconnected – Saving the data locally includes the changes – Use DiffGrams to preserve the changes // Write the data locally ds.WriteXml("local.xml", XmlWriteMode.DiffGram); // Read it locally ds.ReadXml("local.xml", XmlReadMode.DiffGram);

Web Services (4) Updating happens the same way – Limitations of CF DataSets makes it chatty – Prefer to use DiffGrams  though whole DS are still sent Updating happens the same way – Limitations of CF DataSets makes it chatty – Prefer to use DiffGrams  though whole DS are still sent XmlDocument doc = new XmlDocument(); MemoryStream strm = new MemoryStream(); XmlTextWriter writer = new XmlTextWriter(strm, System.Text.Encoding.UTF8); ds.WriteXml(writer, XmlWriteMode.DiffGram); strm.Position = 0; doc.Load(strm); svc.SetDataSet(doc); [WebMethod] public XmlDocument SaveChanges(XmlDocument doc) { MyTypedDs ds = new MyTypedDs(); ds.ReadXml(doc, XmlReadMode.DiffGram); DataSet updated = UpdateDataSet(ds); return new XmlDataDocument(updated); }

DataBinding Performance Issues – DataBinding on devices is very slow  Manually filling-in controls much faster  E.g. 2 seconds vs. 450ms Performance Issues – DataBinding on devices is very slow  Manually filling-in controls much faster  E.g. 2 seconds vs. 450ms // This is faster foreach (DataRow cust in ds.Tables["Customers"].Rows) { listBox1.Items.Add(cust["CompanyName"]); } // This is slower, but more functional listBox1.DataSource = ds.Tables["Customers"]; listBox1.DisplayMember = "CompanyName"; listBox1.ValueMember = "CustomerID";

DataBinding (2) DataBinding is worth it sometimes – If binding multiple items to a single source – If you need a CurrencyManager – If you need Master/Detail Binding DataBinding is worth it sometimes – If binding multiple items to a single source – If you need a CurrencyManager – If you need Master/Detail Binding CurrencyManager mgr = (CurrencyManager)listBox1.BindingContext[ds.Tables["Customers"]]; mgr.Position++; DataTable tbl = ds.Tables["Customers"]; listBox.DataSource = tbl; comboBox.DataSource = tbl; textBox.Bindings.Add("Text", tbl, "CompanyName");

DataBinding (3) – Use of background threads can help // Launch the process on a background thread ThreadPool.QueueUserWorkItem(new WaitCallback(BindDataToForm)); void BindDataToForm(object o) { // Do Data Binding }

SQL Server Mobile Edition What’s New (Replacement for SQL CE) – SQL Server 2005 Integration  API Access to Merge Replication Engine  Download only Tables (read-only)  Partitioned Articles – Synchronization  Sync Progress API’s  Column level Synchronization  Variable Compression Levels  Multiple Subscriptions per DB Table What’s New (Replacement for SQL CE) – SQL Server 2005 Integration  API Access to Merge Replication Engine  Download only Tables (read-only)  Partitioned Articles – Synchronization  Sync Progress API’s  Column level Synchronization  Variable Compression Levels  Multiple Subscriptions per DB Table

SQL Server Mobile Edition (2) What’s New (continued) – Client Storage  Improved ACID Support  Improved Query Processor – Client Performance  Multi-User Support (allow sync while in use)  SqlCeResultSet (Updatable Cursor) – Client Support  Additional Device Support  Including SmartPhone What’s New (continued) – Client Storage  Improved ACID Support  Improved Query Processor – Client Performance  Multi-User Support (allow sync while in use)  SqlCeResultSet (Updatable Cursor) – Client Support  Additional Device Support  Including SmartPhone

Questions?