330 likes | 567 Views
Notes (hidden). PC40. Embedding SQL Server Compact In Desktop And Device Applications. Steve Lasker Program Manager Microsoft Corporation blogs.msdn.com/ SteveLasker. What we'll cover today …. Why data on the client is important How SQL Server Compact “changes the game”
E N D
PC40 Embedding SQL Server Compact In Desktop And Device Applications Steve Lasker Program Manager Microsoft Corporation blogs.msdn.com/SteveLasker
What we'll cover today… • Why data on the client is important • How SQL Server Compact “changes the game” • Performance Best Practices • Differences between Compact & Express • Getting the most by understand the architecture • Interesting ways to leverage local data • Custom Document Format • Run directly from a DVD • Visibility into Client Application Health
Types Of Local Data • Read Only, Reference Data • Is it 100% static for the life of a version? • Are there changes? (list of States, Product Catalog?) • Is it 100% the same for all users? • User Data • Each user has “their data” and they make changes • Orders, My Customers, Settings • Aggregation • Ability to slice and dice on data across various sources
Caching Simplifies Data Access • Offloads detailed questions to the client • Enables local processing, closer to the user Enables offline scenarios Products w/’a’ Products > 5, Products in Category 2, Products Discontinued, Most sold products for last 3 months Top Products for My Customers What’s changed for my data Added, Updated, Deleted
Enabling data movement from the smallest device, capturing data at the point of activity through the largest data center, to the offsite cloud Cloud From embedded devices to desktops From desktop to data center To hosted services Clients Servers Synchronizing data from the point of activity to the data center
One Size Fits All? • Best practices, not all that different • Architectural differences, but suited to the task • Choose your weapon
demo How Compact “Changes The Game” What good is a database if you can’t deploy it?
Deploying Target = Any • Change Managed Provider reference to Copy Local = true • Include both 32 and 64 bit Compact engine dlls • Place 32bit version under an X86 • Place 64bit version under AMD64 • AMD64 includes Intel X64Folder Name based off: Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
Architectural Comparison One Size Fits All?
Demo Performance Best Practices SqlCeCommandcmd = conn.CreateCommand();cmd.Parameters.Add("@name", System.Data.SqlDbType.NVarChar, 50);while (reader.Read()) {cmd.CommandText = "INSERT INTO Customer (CustomerId, Name) VALUES(@id, @name";cmd.Parameters["@customerId"].Value = id; Eeeking out that extra bit of performance
Best Practices – Performance • Parameterized Commands, with type and precision SqlCeCommandcmd = conn.CreateCommand();cmd.Parameters.Add("@customerId", System.Data.SqlDbType.Int);cmd.Parameters.Add("@name", System.Data.SqlDbType.NVarChar, 50);cmd.CommandText = "INSERT INTO Customer (CustomerId, Name) VALUES(@id, @name");while (reader.Read()) {cmd.Parameters["@customerId"].Value = id; cmd.Parameters["@name"].Value = name; • Bulk Insert w/SqlCeResultSet cmd.CommandText = "Customer"; cmd.CommandType = System.Data.CommandType.TableDirect; SqlCeResultSetrst = cmd.ExecuteResultSet(ResultSetOptions.Updatable); SqlCeUpdatableRecordnewRow; while (reader.Read()) {newRow = rst.CreateRecord(); newRow["customerId"] = customerId; newRow[“name"] = name; rst.Insert(newRow);
Monitoring Client Health Acme Widgets ? Data Center • How to see what’s happening at the client? • Clients aren’t reachable • Either aren’t Online when you need them • Or they’re not addressable with a static IP • What to do? • Phone home?
Web Service TraceListner Acme Widgets Data Center try { productInfo = productSvc.GetProductInf(barcode); } catch (NetworkException ex) { Trace.WriteLine(“UnableToConnect - " + ex.Message, “Product Lookup") } try { barcode = scanner.Scan(); } catch (Exception ex) { Trace.WriteLine("Scan Failed - " + ex.Message, "Barcode Scanner"); } Trace.Listeners.Add(newWebServiceTraceListner("http://MyTraceService.svc")) Web Service TraceListener
SQL Server Compact TraceListner Acme Widgets Data Center try { productInfo = productSvc.GetProductInf(barcode); } catch (NetworkException ex) { Trace.WriteLine(“UnableToConnect - " + ex.Message, “Product Lookup") } Trace.Listeners.Add(newSqlCeTraceListner("Log.sdf", "http://LogSyncService.svc")); Compact TraceListener Sync Services to move Log info when a connection is available
demo Using Trace Listener to Gather Information in the Field Getting visibility to what’s actually going on
SQL Server Compact TraceListener Acme Widgets Data Center
Custom Doc Formats • Structured document • Single file, code free, email attachment safe • Post “Documents” to SharePoint • Create custom extensions, map to your app • Password protect, requiring users to open documents w/your app • File Associations Supported by Visual Studio 2008 & ClickOnce
demo Using a SQL Server Compact Database as a Document ClickOnce, w/.NET FX 3.5 enables file associations
Recap • Why data on the client is important • Power of the client, freedom to add value • How SQL Server Compact “changes the game” • No need to worry about deployment • Performance Best Practices • Take advantage of the in-proc nature • Interesting ways to leverage local data • Custom Document Format • Run directly from a DVD • Visibility into Client Application Health
Summary • SQL Server Compact • ~1mb embedded database, no brainer deployment • It’s free, fast, safe/encryptable and compact • It’s easy to program and manage • Single file, code free, doc centric file format • It’s an alternative to JET, XML, Persisted DataSets, SQL Server Express • It’s integrated into: • Visual Studio 2005 SP1 • Visual Studio 2008 (Orcas) • Adds Sync Services for ADO.NET • SQL Server Management Studio 2008 (Katmai) • 3.1 In ROM for Windows Mobile 6.x
Related Content TL40 Microsoft Sync Framework Advances – Lev Novik Day 1 PC45 WPF: Data-centric Applications Using the DataGrid and Ribbon Controls - Samantha Durante, Mark Wilson-Thomas Day 4-Noon TL08 Offline-Enabled Data Services and Desktop Applications – Pablo Castro Day 3 BB15 SQL Server: Database to Data Platform - Road from Server to Devices to the Cloud – David Campbell Day 1 BB40 Sync Framework: Enterprise Data in the Cloud and on Devices – Liam Cavanaugh Day 2
SQL Server Compact Resources • SQL Server Compactwww.Microsoft.com/SQL/Compact • SQL Server Compact Q&ABlogs.msdn.com/SqlServerCompactBlogs.msdn.com/SteveLaskerBlogs.msdn.com/Laxmi • BooksMicrosoft SQL Server 2005 Compact - PrashantDhingraHitchhikerGuides.net - Bill VaughnSQL Server Compact - Jose M. Torres Windows Mobile Data Synchronization – Rob Tiffany • ToolsPrimeworksGUI Innovations • Microsoft Synchronization Services for ADO.NETMSDN.Microsoft.com/Syncblogs.msdn.com/Synchronizer
Evals & Recordings Please fill out your evaluation for this session at: This session will be available as a recording at: www.microsoftpdc.com
SQL Server Compact Resources • SQL Server Compactwww.Microsoft.com/SQL/Compact • SQL Server Compact Q&ABlogs.msdn.com/SqlServerCompactBlogs.msdn.com/SteveLaskerBlogs.msdn.com/Laxmi • BooksMicrosoft SQL Server 2005 Compact - PrashantDhingraHitchhikerGuides.net - Bill VaughnSQL Server Compact - Jose M. Torres Windows Mobile Data Synchronization – Rob Tiffany • ToolsPrimeworksGUI Innovations • Microsoft Synchronization Services for ADO.NETMSDN.Microsoft.com/Syncblogs.msdn.com/Synchronizer
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.