Published on

Published in: Business, Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Hello and welcome to this session on SQL Server Mobile Edition Data Access. My name is ___________________.
  • Mobile

    1. 1. Data Access with SQL Server 2005 Mobile Edition and the .NET Compact Framework v2.0 Scott Colestock
    2. 2. Agenda <ul><li>Overview – SQL Mobile Architecture </li></ul><ul><li>SQL Server 2005 Integration </li></ul><ul><li>Visual Studio 2005 Integration </li></ul><ul><li>Merge Replication </li></ul>
    3. 3. Overview Device Data Access Native Stack Managed Stack SQL Server Mobile Edition CLR / .NET CF SQL Server CE Data Provider ADO.NET VB .NET / C# VS 2005 C++ OLEDB CE OLEDB Provider QP / Cursor Engine / ES Storage Engine / Replication Tracking
    4. 4. Overview Highly Integrated into Development Tools <ul><li>Integration with SQL Server 2005 </li></ul><ul><ul><li>DTS Support </li></ul></ul><ul><ul><li>Show Plan and Hints </li></ul></ul><ul><ul><li>SQL Server Management Studio </li></ul></ul><ul><li>Integration with Visual Studio 2005 </li></ul><ul><ul><li>Ships with Visual Studio 2005 </li></ul></ul><ul><ul><li>Database management functionality </li></ul></ul><ul><ul><li>Easy code upgrades from SQL Server CE 2.0 </li></ul></ul>
    5. 5. Overview Architecture Improvements <ul><li>Storage engine </li></ul><ul><ul><li>Multiconnection support </li></ul></ul><ul><ul><li>Row level locking of data </li></ul></ul><ul><ul><li>Shares common memory pool </li></ul></ul><ul><ul><li>Auto-shrink support </li></ul></ul><ul><li>Improved query processor </li></ul><ul><ul><li>Cost-based optimization </li></ul></ul><ul><ul><li>Show plan and query hints </li></ul></ul><ul><ul><li>Scrollable, updatable cursor – SqlCeResultSet </li></ul></ul>
    6. 6. Overview Synchronization Improvements <ul><li>Improved synchronization control </li></ul><ul><ul><li>Multiuser synchronization </li></ul></ul><ul><ul><li>Progress notifications </li></ul></ul><ul><ul><li>Multiple subscriptions in the same database </li></ul></ul><ul><li>Synchronization performance (w/SQL 2005) </li></ul><ul><ul><li>Partitioned articles </li></ul></ul><ul><ul><li>Download-only tables </li></ul></ul><ul><ul><li>Column-level tracking </li></ul></ul>
    7. 7. Overview Introducing the SqlCeResultSet <ul><li>Development Features </li></ul><ul><ul><li>Included in SQL Mobile, ships with: </li></ul></ul><ul><ul><ul><li>Visual Studio 2005 </li></ul></ul></ul><ul><ul><ul><li>SQL Server 2005 </li></ul></ul></ul><ul><ul><li>Takes full advantage of SQL Server 2005 Mobile Edition local capabilities </li></ul></ul><ul><li>Extended Features </li></ul><ul><ul><li>Scrolling access </li></ul></ul><ul><ul><li>Update in place </li></ul></ul><ul><ul><li>Random access </li></ul></ul>
    8. 8. SQL Server 2005 Integration SQL Server 2005 Tools <ul><ul><li>Business Intelligence Development Studio </li></ul></ul><ul><ul><ul><li>Visual Tools for creating Data Transformation </li></ul></ul></ul><ul><ul><ul><li>Data Visualization </li></ul></ul></ul><ul><ul><ul><li>Enhanced Debugging </li></ul></ul></ul>
    9. 9. SQL Server 2005 Integration SQL Server 2005 Tools <ul><ul><li>SQL Server Management Studio </li></ul></ul><ul><ul><ul><li>Create SQL Mobile Databases </li></ul></ul></ul><ul><ul><ul><li>Show Plan and Hints </li></ul></ul></ul><ul><ul><ul><li>Faster Optimization </li></ul></ul></ul><ul><ul><ul><li>Enhanced Publication </li></ul></ul></ul><ul><ul><ul><li>Subscription Wizard </li></ul></ul></ul>
    10. 10. SQL Server 2005 Integration
    11. 11. Visual Studio 2005 Integration Visual Studio Tools <ul><li>Flexible Development </li></ul><ul><ul><li>Native and managed development environment </li></ul></ul><ul><ul><li>Visual Basic . NET, Visual C++, Visual C# all localized in the IDE </li></ul></ul><ul><ul><li>Targets multiple devices </li></ul></ul>
    12. 12. Visual Studio 2005 Integration Visual Studio Tools <ul><li>Rapid Development </li></ul><ul><ul><li>Data designer support via Visual Studio 2005 IDE </li></ul></ul><ul><ul><li>Drag and drop controls onto form and automatically bind </li></ul></ul>
    13. 13. Visual Studio 2005 Integration Visual Studio Tools <ul><li>Library Evolution </li></ul><ul><ul><li>SqlCeEngine, SqlCeConnection, SqlCeCommand, SqlCeDataReader </li></ul></ul><ul><ul><li>SqlCeResultSet (new updatable scrollable cursor) </li></ul></ul>
    14. 14. Visual Studio 2005 Integration
    15. 15. Synchronization Goals of Synchronization <ul><li>Simplify development of synchronization logic </li></ul><ul><ul><li>Sync becomes a single line of code </li></ul></ul><ul><ul><li>Conflict resolution happens on the server through SQL Server model </li></ul></ul><ul><li>Share a common (mobile) data source </li></ul><ul><ul><li>Allow multiuser access to the same data source </li></ul></ul><ul><ul><ul><li>(that lives on the device) </li></ul></ul></ul><ul><ul><li>Improve performance and data concurrency </li></ul></ul><ul><li>More end-user versatility </li></ul><ul><ul><li>Allows end users to change devices and still access the data source </li></ul></ul>
    16. 16. Synchronization Overall Architecture OLE DB SQL Mobile Client Agent HTTP OLE DB SQL Mobile Engine SQL Server OLE DB Provider SQL Mobile Server Agent Internet Information Services (IIS) Application Mobile Database SQL Server Database
    17. 17. Synchronization Outlining Your Options <ul><li>SQL Server Mobile Edition provides two synchronization solutions </li></ul><ul><ul><li>Remote Data Access (RDA) </li></ul></ul><ul><ul><li>Merge replication </li></ul></ul><ul><li>Both require server components that are on IIS. </li></ul>
    18. 18. Remote Data Access Overview <ul><li>Loosely coupled connectivity between SQL Server Mobile Edition and SQL Server </li></ul><ul><ul><li>No configuration of the back-end Sql Server required </li></ul></ul><ul><ul><li>Client application specifies query to return data for a local table (table-at-a-time metaphor) </li></ul></ul><ul><ul><li>Optionally tracks changes locally </li></ul></ul><ul><ul><li>Sends locally changed records back to SQL Server </li></ul></ul><ul><li>The .NET Compact Framework provides managed wrapper </li></ul><ul><ul><li>SqlCeRemoteDataAccess </li></ul></ul>
    19. 19. Remote Data Access Using SqlCeRemoteDataAccess <ul><li>An application must specify RDA connectivity parameters </li></ul><ul><ul><li>Web server information </li></ul></ul><ul><ul><ul><li>URL – must include sqlcesa30.dll </li></ul></ul></ul><ul><ul><ul><li>Login and password </li></ul></ul></ul><ul><ul><li>Local database information (SQL Mobile Edition OLE DB connection string) </li></ul></ul><ul><ul><li>Proxy server login and password information </li></ul></ul><ul><li>Remote DB info sent with each command (SQL Connection String) </li></ul>
    20. 20. Remote Data Access Pull Operation <ul><li>Local table created including data and schema </li></ul><ul><ul><li>Optionally includes primary key </li></ul></ul><ul><ul><li>Optionally includes indexes </li></ul></ul><ul><li>Values may come from a table or stored procedure </li></ul><ul><ul><li>Can retrieve all data for complete data set or… </li></ul></ul><ul><ul><li>Can filter data to reduce data size </li></ul></ul><ul><ul><li>View/stored procedure can reference only one table with a primary key </li></ul></ul>
    21. 21. Remote Data Access Pull Operation <ul><li>Optionally track local changes </li></ul><ul><ul><li>Changes can be later applied </li></ul></ul><ul><ul><li>Uses optimistic concurrency (no server data locked) </li></ul></ul><ul><li>Local table must not exist before pull </li></ul><ul><ul><li>Created during pull operation </li></ul></ul><ul><ul><li>Error thrown if table exists </li></ul></ul>
    22. 22. Remote Data Access Using RDA Pull Public Sub RDAPull() Dim rda as New SqlCeRemoteDataAccess Dim ServerOledbStr as String = “ Provider=sqloledb; Data Source=dataserver;” _ “ Initial Catalog=Pubs;User Id=sa;Password=;” rda.LocalConnectionString = ” Provider=Data Source=My Documents est.sdf” ‘ Set URL and IIS login/password. rda.InternetUrl = “” rda.Pull( “ Authors”, _ “ Select * from authors where state = ‘CA’”, _ ServerOledbStr, _ RdaTrackOption.TrackingOn) End Sub
    23. 23. Remote Data Access Push Operation <ul><li>Sends changes back to server </li></ul><ul><ul><li>All changes since last pull or push are applied </li></ul></ul><ul><ul><li>Changes applied to server indiscriminately </li></ul></ul><ul><li>Table tracking must have been specified during pull operation </li></ul><ul><li>Can choose if updates batched as one transaction, or distinct </li></ul><ul><li>Can have conflicts logged in Errors table </li></ul>
    24. 24. Remote Data Access Using RDA Push Public Sub RDAPush() Dim rda = New SqlCeRemoteDataAccess() Dim ServerOledbStr as String = “ Provider=sqloledb; Data Source=dataserver;” _ “ Initial Catalog=Pubs;User Id=sa;Password=;” rda.LocalConnectionString = _ ” Data Source=My Documents est.sdf” ‘ Set URL and IIS login/password. rda.InternetUrl = “” rda.Push( “ Authors”, ServerOledbStr, RdaBatchOption.BatchingOn) End Sub
    25. 25. Merge Replication Overview <ul><li>Provides data synchronization between SQL Server 2005 Mobile Edition and SQL Server </li></ul><ul><ul><li>SQL Server is the publisher </li></ul></ul><ul><ul><li>SQL Server 2005 Mobile Edition is the subscriber </li></ul></ul><ul><li>SQL Server 2005 Mobile Edition receives initial snapshot from SQL Server </li></ul><ul><li>Both SQL Server 2005 Mobile Edition and SQL Server can modify the data </li></ul><ul><ul><li>Conflict resolution can be customized </li></ul></ul>
    26. 26. Merge Replication Overview <ul><li>Changes reconciled on next synchronization </li></ul><ul><ul><li>Local SQL Server 2005 Mobile Edition changes sent to SQL Server </li></ul></ul><ul><ul><li>SQL Server changes sent to SQL Server 2005 Mobile Edition </li></ul></ul><ul><li>SQL Server Management Studio wizards </li></ul><ul><ul><li>Publishers created in studio </li></ul></ul><ul><ul><li>Subscribers create in studio </li></ul></ul><ul><li>.NET Compact Framework managed wrapper - SqlCeReplication </li></ul>
    27. 27. Merge Replication Examining the Code Public Sub SyncSubscription() Dim repl as New SqlCeReplication() repl.InternetUrl = &quot;http://Server1/SQLServerCE/sqlcesa30.dll&quot; repl.Publisher = “SERVER1&quot; repl.PublisherDatabase = “CustmerInfo&quot; repl.PublisherLogin = &quot;sa&quot; repl.PublisherPassword = &quot;&quot; repl.Publication = &quot;CustomerInfoPub&quot; repl.SubscriberConnectionString = _ ” Data Source=My DocumentsMyLocalDB.sdf“ repl.Subscriber = “CustomerInfoSub&quot; repl.AddSubscription(AddOption.CreateDatabase) repl.Synchronize() End Sub
    28. 28. Merge Replication Weighing the Costs <ul><li>Several triggers and stored procedures added </li></ul><ul><ul><li>Added to system tables </li></ul></ul><ul><ul><li>Adds more overhead </li></ul></ul><ul><li>Replicated tables must have a ROWGUIDCOL </li></ul><ul><ul><li>Ensures that rows are unique </li></ul></ul><ul><ul><li>Can avoid if rowguid column is added prior </li></ul></ul><ul><li>Database must track all modifications </li></ul><ul><ul><li>Additional tables added to system database </li></ul></ul><ul><ul><li>Tables used to track modifications </li></ul></ul><ul><ul><li>Can grow significantly </li></ul></ul>
    29. 29. Merge Replication Minimizing the Costs for Device Applications <ul><li>Key to success for device apps is minimizing communication </li></ul><ul><ul><li>Take only what you need </li></ul></ul><ul><ul><li>Apply filters </li></ul></ul><ul><ul><ul><li>Static or Parameterized </li></ul></ul></ul><ul><ul><ul><li>Join </li></ul></ul></ul><ul><ul><ul><li>Column </li></ul></ul></ul><ul><li>Reducing the amount of data sent between devices and server… </li></ul><ul><ul><li>Reduces sync time </li></ul></ul><ul><ul><li>Improves responsiveness </li></ul></ul>
    30. 30. Exploring Merge Replication
    31. 31. Making The Replication Choice Recommendations <ul><li>Remote Data Access </li></ul><ul><ul><li>If you can’t modify the backend database… </li></ul></ul><ul><ul><li>If you have small tables to bring to the device… </li></ul></ul><ul><ul><li>If the tables you modify are distinct from those you reference… </li></ul></ul><ul><li>Choose merge replication </li></ul><ul><ul><li>Bi-directional synchronization on all tables – only the deltas are transferred </li></ul></ul><ul><ul><li>Much more flexible conflict resolution </li></ul></ul><ul><li>For more on making the choice </li></ul><ul><ul><ul><li> html/eff_arch_sql_servr_ce_rep.asp </li></ul></ul></ul><ul><ul><ul><li>“ Comparing Remote Data Access (RDA) and Merge Replication” in SQL 2005 BOL </li></ul></ul></ul>
    32. 32. Summary <ul><li>SQL Server 2005 Mobile Edition functionality is greatly enhanced for developers </li></ul><ul><li>Integration with SQL Server 2005 makes generation and maintenance of SQL Mobile databases better </li></ul><ul><li>Integration with Visual Studio 2005 makes developing of SQL Mobile applications easier and faster </li></ul><ul><li>Remote data access vs. merge replication </li></ul>
    33. 33. Heartland Developers Conference ’05 <ul><li>October 13 – 14, Cedar Rapids, IA </li></ul><ul><li>TWICE THE SIZE (days, sessions, attendees, parties) </li></ul><ul><li>Developer Pre-Party on the 12 th and Developer Jam on the 13 th </li></ul><ul><li>2 Keynotes, 18 Sessions, Developer Lounges </li></ul><ul><li>2 Tracks: Center Stage / Behind the Curtain </li></ul><ul><li>Many door prizes including a top of the line Alienware Laptop! </li></ul><ul><li> </li></ul>
    34. 34. © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY. Content created by 3 Leaf Solutions