35
Data Access with SQL Data Access with SQL Server 2005 Mobile Server 2005 Mobile Edition and the .NET Edition and the .NET Compact Framework Compact Framework v2.0 v2.0 Scott Colestock Scott Colestock

Mobile

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Mobile

Data Access with SQL Data Access with SQL Server 2005 Mobile Server 2005 Mobile Edition and the .NET Edition and the .NET Compact Framework Compact Framework v2.0v2.0Scott ColestockScott Colestock

Page 2: Mobile

AgendaAgenda

Overview – SQL Mobile ArchitectureOverview – SQL Mobile Architecture

SQL Server 2005 IntegrationSQL Server 2005 Integration

Visual Studio 2005 IntegrationVisual Studio 2005 Integration

Merge ReplicationMerge Replication

Page 3: Mobile

OverviewOverviewDeviceDevice DataData AccessAccess

Native Stack Managed Stack

SQL Server Mobile Edition

CLR / .NET CFCLR / .NET CF

SQL Server CE SQL Server CE Data ProviderData Provider

ADO.NETADO.NET

VB .NET / C#VB .NET / C#VS 2005 C++VS 2005 C++

OLEDB CEOLEDB CE

OLEDB OLEDB ProviderProvider

QP / Cursor Engine / ESQP / Cursor Engine / ES

Storage Engine / Replication TrackingStorage Engine / Replication Tracking

Page 4: Mobile

OverviewOverviewHighlyHighly IntegratedIntegrated intointo DevelopmentDevelopment ToolsTools

Integration with SQL Server 2005Integration with SQL Server 2005DTS SupportDTS Support

Show Plan and HintsShow Plan and Hints

SQL Server Management StudioSQL Server Management Studio

Integration with Visual Studio 2005Integration with Visual Studio 2005Ships with Visual Studio 2005Ships with Visual Studio 2005

Database management functionalityDatabase management functionality

Easy code upgrades from SQL Server CE Easy code upgrades from SQL Server CE 2.02.0

Page 5: Mobile

OverviewOverviewArchitecture ImprovementsArchitecture Improvements

Storage engineStorage engineMulticonnection supportMulticonnection support

Row level locking of data Row level locking of data

Shares common memory poolShares common memory pool

Auto-shrink supportAuto-shrink support

Improved query processorImproved query processorCost-based optimization Cost-based optimization

Show plan and query hintsShow plan and query hints

Scrollable, updatable cursor – Scrollable, updatable cursor – SqlCeResultSetSqlCeResultSet

Page 6: Mobile

OverviewOverviewSynchronization ImprovementsSynchronization Improvements

Improved synchronization controlImproved synchronization controlMultiuser synchronizationMultiuser synchronization

Progress notificationsProgress notifications

Multiple subscriptions in the same Multiple subscriptions in the same databasedatabase

Synchronization performance (w/SQL Synchronization performance (w/SQL 2005)2005)

Partitioned articlesPartitioned articles

Download-only tablesDownload-only tables

Column-level trackingColumn-level tracking

Page 7: Mobile

OverviewOverviewIntroducing the SqlCeResultSetIntroducing the SqlCeResultSet

Development FeaturesDevelopment FeaturesIncluded in SQL Mobile, ships with:Included in SQL Mobile, ships with:

Visual Studio 2005Visual Studio 2005

SQL Server 2005SQL Server 2005

Takes full advantage of SQL Server 2005 Takes full advantage of SQL Server 2005 Mobile Edition local capabilitiesMobile Edition local capabilities

Extended FeaturesExtended FeaturesScrolling accessScrolling access

Update in placeUpdate in place

Random accessRandom access

Page 8: Mobile

SQL Server 2005 IntegrationSQL Server 2005 IntegrationSQL Server 2005 ToolsSQL Server 2005 Tools

Business Intelligence Development Business Intelligence Development StudioStudio

Visual Tools for creating Data TransformationVisual Tools for creating Data Transformation

Data VisualizationData Visualization

Enhanced DebuggingEnhanced Debugging

Page 9: Mobile

SQL Server 2005 IntegrationSQL Server 2005 IntegrationSQL Server 2005 ToolsSQL Server 2005 Tools

SQL Server Management StudioSQL Server Management StudioCreate SQL Mobile DatabasesCreate SQL Mobile Databases

Show Plan and HintsShow Plan and Hints

Faster OptimizationFaster Optimization

Enhanced PublicationEnhanced Publication

Subscription WizardSubscription Wizard

Page 10: Mobile

SQL Server 2005 SQL Server 2005 IntegrationIntegrationSQL Server 2005 SQL Server 2005 IntegrationIntegration

Page 11: Mobile

Visual Studio 2005 Visual Studio 2005 IntegrationIntegrationVisual Studio ToolsVisual Studio Tools

Flexible Flexible DevelopmentDevelopment

Native and Native and managed managed development development environmentenvironment

Visual Basic . NET, Visual Basic . NET, Visual C++, Visual Visual C++, Visual C# all localized in C# all localized in the IDEthe IDE

Targets multiple Targets multiple devicesdevices

Page 12: Mobile

Visual Studio 2005 Visual Studio 2005 IntegrationIntegrationVisual Studio ToolsVisual Studio Tools

Rapid Rapid DevelopmentDevelopment

Data designer Data designer support via Visual support via Visual Studio 2005 IDEStudio 2005 IDE

Drag and drop Drag and drop controls onto form controls onto form and automatically and automatically bindbind

Page 13: Mobile

Visual Studio 2005 Visual Studio 2005 IntegrationIntegrationVisual Studio ToolsVisual Studio Tools

Library EvolutionLibrary EvolutionSqlCeEngine, SqlCeEngine, SqlCeConnection, SqlCeConnection, SqlCeCommand, SqlCeCommand, SqlCeDataReaderSqlCeDataReader

SqlCeResultSet SqlCeResultSet (new updatable (new updatable scrollable cursor)scrollable cursor)

Page 14: Mobile

Visual Studio 2005 Visual Studio 2005 IntegrationIntegrationVisual Studio 2005 Visual Studio 2005 IntegrationIntegration

Page 15: Mobile

SynchronizationSynchronizationGoals of SynchronizationGoals of Synchronization

Simplify development of synchronization Simplify development of synchronization logiclogic

Sync becomes a single line of codeSync becomes a single line of code

Conflict resolution happens on the server Conflict resolution happens on the server through SQL Server modelthrough SQL Server model

Share a common (mobile) data sourceShare a common (mobile) data sourceAllow multiuser access to the same data sourceAllow multiuser access to the same data source(that lives on the device)(that lives on the device)

Improve performance and data concurrencyImprove performance and data concurrency

More end-user versatilityMore end-user versatilityAllows end users to change devices and still Allows end users to change devices and still access the data sourceaccess the data source

Page 16: Mobile

OL

E D

B

SQL Mobile Client SQL Mobile Client AgentAgent

SynchronizationSynchronizationOverallOverall ArchitectureArchitecture

HTTP OLE DB

ApplicationApplication

SQL Mobile Engine

MobileMobileDatabaseDatabase

SQL ServerSQL ServerDatabaseDatabase

SQL Server SQL Server OLE DBOLE DBProviderProvider

SQL Mobile ServerSQL Mobile ServerAgentAgent

Internet Information Internet Information Services (IIS)Services (IIS)

Page 17: Mobile

SynchronizationSynchronizationOutliningOutlining YourYour OptionsOptions

SQL Server Mobile Edition provides SQL Server Mobile Edition provides two synchronization solutionstwo synchronization solutions

Remote Data Access (RDA)Remote Data Access (RDA)

Merge replicationMerge replication

Both require server components that Both require server components that are on IIS.are on IIS.

Page 18: Mobile

Remote Data Access Remote Data Access OverviewOverview

Loosely coupled connectivity between SQL Loosely coupled connectivity between SQL Server Mobile Edition and SQL ServerServer Mobile Edition and SQL Server

No configuration of the back-end Sql Server No configuration of the back-end Sql Server requiredrequired

Client application specifies query to return data Client application specifies query to return data for a local table (table-at-a-time metaphor)for a local table (table-at-a-time metaphor)

Optionally tracks changes locallyOptionally tracks changes locally

Sends locally changed records back to SQL Sends locally changed records back to SQL ServerServer

The .NET Compact Framework provides The .NET Compact Framework provides managed wrappermanaged wrapper

SqlCeRemoteDataAccessSqlCeRemoteDataAccess

Page 19: Mobile

Remote Data AccessRemote Data AccessUsingUsing SqlCeRemoteDataAccessSqlCeRemoteDataAccess

An application must specify RDA An application must specify RDA connectivity parametersconnectivity parameters

Web server informationWeb server informationURL – must include sqlcesa30.dllURL – must include sqlcesa30.dll

Login and passwordLogin and password

Local database information (SQL Mobile Local database information (SQL Mobile Edition OLE DB connection string)Edition OLE DB connection string)

Proxy server login and password Proxy server login and password information information

Remote DB info sent with each Remote DB info sent with each command (SQL Connection String)command (SQL Connection String)

Page 20: Mobile

Remote Data AccessRemote Data AccessPullPull OperationOperation

Local table created including data Local table created including data and schemaand schema

Optionally includes primary key Optionally includes primary key

Optionally includes indexesOptionally includes indexes

Values may come from a table or Values may come from a table or stored procedurestored procedure

Can retrieve all data for complete data set or…Can retrieve all data for complete data set or…

Can filter data to reduce data sizeCan filter data to reduce data size

View/stored procedure can reference only one table with a View/stored procedure can reference only one table with a primary keyprimary key

Page 21: Mobile

Remote Data AccessRemote Data AccessPullPull OperationOperation

Optionally track local changesOptionally track local changesChanges can be later appliedChanges can be later applied

Uses optimistic concurrency (no server Uses optimistic concurrency (no server data locked)data locked)

Local table must not exist before pullLocal table must not exist before pullCreated during pull operationCreated during pull operation

Error thrown if table existsError thrown if table exists

Page 22: Mobile

Remote Data AccessRemote Data AccessUsingUsing RDARDA PullPull

Public Sub RDAPull()Public Sub RDAPull() Dim rda as New Dim rda as New SqlCeRemoteDataAccessSqlCeRemoteDataAccess Dim ServerOledbStr as String = Dim ServerOledbStr as String = “ “Provider=sqloledb; Data Source=dataserver;” _Provider=sqloledb; Data Source=dataserver;” _ “ “Initial Catalog=Pubs;User Id=sa;Password=;”Initial Catalog=Pubs;User Id=sa;Password=;”

rda.LocalConnectionString = rda.LocalConnectionString = ” ”Provider=Data Source=\My Documents\test.sdf”Provider=Data Source=\My Documents\test.sdf” ‘ Set URL and IIS login/password. rda.InternetUrl = “http://www.adventure-works.com/sqlmobile/sqlcesa30.dll”

rda.Pull(rda.Pull( “ “Authors”, _Authors”, _ “ “Select * from authors where state = ‘CA’”, _Select * from authors where state = ‘CA’”, _ ServerOledbStr, _ServerOledbStr, _ RdaTrackOption.TrackingOn)RdaTrackOption.TrackingOn)End SubEnd Sub

Page 23: Mobile

Remote Data AccessRemote Data AccessPushPush OperationOperation

Sends changes back to serverSends changes back to serverAll changes since last pull or push are All changes since last pull or push are appliedapplied

Changes applied to server Changes applied to server indiscriminatelyindiscriminately

Table tracking must have been Table tracking must have been specified during pull operationspecified during pull operation

Can choose if updates batched as Can choose if updates batched as one transaction, or distinctone transaction, or distinct

Can have conflicts logged in Errors Can have conflicts logged in Errors tabletable

Page 24: Mobile

Remote Data AccessRemote Data AccessUsingUsing RDARDA PushPush

Public Sub RDAPush()Public Sub RDAPush() Dim rda = New SqlCeRemoteDataAccess()Dim rda = New SqlCeRemoteDataAccess()

Dim ServerOledbStr as String = Dim ServerOledbStr as String = “ “Provider=sqloledb; Data Source=dataserver;” _Provider=sqloledb; Data Source=dataserver;” _ “ “Initial Catalog=Pubs;User Id=sa;Password=;”Initial Catalog=Pubs;User Id=sa;Password=;”

rda.LocalConnectionString = _rda.LocalConnectionString = _””Data Source=\My Documents\test.sdf”Data Source=\My Documents\test.sdf”

‘ ‘ Set URL and IIS login/password.Set URL and IIS login/password. rda.InternetUrl = rda.InternetUrl = “http://www.adventure-works.com/sqlmobile/sqlcesa30.dll”“http://www.adventure-works.com/sqlmobile/sqlcesa30.dll”

rda.Push(rda.Push( “ “Authors”,Authors”, ServerOledbStr,ServerOledbStr, RdaBatchOption.BatchingOn)RdaBatchOption.BatchingOn)End SubEnd Sub

Page 25: Mobile

Merge ReplicationMerge ReplicationOverviewOverview

Provides data synchronization Provides data synchronization between SQL Server 2005 Mobile between SQL Server 2005 Mobile Edition and SQL ServerEdition and SQL Server

SQL Server is the publisherSQL Server is the publisher

SQL Server 2005 Mobile Edition is the SQL Server 2005 Mobile Edition is the subscribersubscriber

SQL Server 2005 Mobile Edition SQL Server 2005 Mobile Edition receives initial snapshot from SQL receives initial snapshot from SQL ServerServer

Both SQL Server 2005 Mobile Edition Both SQL Server 2005 Mobile Edition and SQL Server can modify the dataand SQL Server can modify the data

Conflict resolution can be customizedConflict resolution can be customized

Page 26: Mobile

Merge ReplicationMerge ReplicationOverviewOverview

Changes reconciled on next Changes reconciled on next synchronizationsynchronization

Local SQL Server 2005 Mobile Edition Local SQL Server 2005 Mobile Edition changes sent to SQL Serverchanges sent to SQL Server

SQL Server changes sent to SQL Server SQL Server changes sent to SQL Server 2005 Mobile Edition 2005 Mobile Edition

SQL Server Management Studio SQL Server Management Studio wizardswizards

Publishers created in studioPublishers created in studio

Subscribers create in studioSubscribers create in studio

.NET Compact Framework managed .NET Compact Framework managed wrapper - SqlCeReplicationwrapper - SqlCeReplication

Page 27: Mobile

Merge ReplicationMerge ReplicationExaminingExamining thethe CodeCode

Public Sub SyncSubscription()Public Sub SyncSubscription() Dim repl as New SqlCeReplication()Dim repl as New SqlCeReplication() repl.InternetUrl = repl.InternetUrl = "http://Server1/SQLServerCE/sqlcesa30.dll""http://Server1/SQLServerCE/sqlcesa30.dll" repl.Publisher = “SERVER1"repl.Publisher = “SERVER1" repl.PublisherDatabase = “CustmerInfo"repl.PublisherDatabase = “CustmerInfo" repl.PublisherLogin = "sa"repl.PublisherLogin = "sa" repl.PublisherPassword = ""repl.PublisherPassword = "" repl.Publication = "CustomerInfoPub"repl.Publication = "CustomerInfoPub" repl.SubscriberConnectionString = _repl.SubscriberConnectionString = _

””Data Source=\My Documents\MyLocalDB.sdf“Data Source=\My Documents\MyLocalDB.sdf“

repl.Subscriber = “CustomerInfoSub"repl.Subscriber = “CustomerInfoSub" repl.AddSubscription(AddOption.CreateDatabase)repl.AddSubscription(AddOption.CreateDatabase) repl.Synchronize()repl.Synchronize()End SubEnd Sub

Page 28: Mobile

Merge ReplicationMerge ReplicationWeighingWeighing thethe CostsCosts

Several triggers and stored Several triggers and stored procedures addedprocedures added

Added to system tablesAdded to system tablesAdds more overheadAdds more overhead

Replicated tables must have a Replicated tables must have a ROWGUIDCOLROWGUIDCOL

Ensures that rows are uniqueEnsures that rows are uniqueCan avoid if rowguid column is added Can avoid if rowguid column is added priorprior

Database must track all modificationsDatabase must track all modificationsAdditional tables added to system Additional tables added to system databasedatabaseTables used to track modificationsTables used to track modificationsCan grow significantlyCan grow significantly

Page 29: Mobile

Merge ReplicationMerge ReplicationMinimizingMinimizing thethe CostsCosts forfor DeviceDevice ApplicationsApplications

Key to success for device apps is Key to success for device apps is minimizing communicationminimizing communication

Take only what you needTake only what you needApply filtersApply filters

Static or ParameterizedStatic or ParameterizedJoinJoinColumnColumn

Reducing the amount of data sent Reducing the amount of data sent between devices and server…between devices and server…

Reduces sync timeReduces sync timeImproves responsivenessImproves responsiveness

Page 30: Mobile

Exploring Merge Exploring Merge ReplicationReplicationExploring Merge Exploring Merge ReplicationReplication

Page 31: Mobile

Making The Replication Making The Replication ChoiceChoiceRecommendationsRecommendations

Remote Data AccessRemote Data AccessIf you can’t modify the backend database…If you can’t modify the backend database…If you have small tables to bring to the device…If you have small tables to bring to the device…If the tables you modify are distinct from those If the tables you modify are distinct from those you reference…you reference…

Choose merge replicationChoose merge replicationBi-directional synchronization on all tables – only Bi-directional synchronization on all tables – only the deltas are transferredthe deltas are transferredMuch more flexible conflict resolutionMuch more flexible conflict resolution

For more on making the choiceFor more on making the choicehttp://msdn.microsoft.com/library/en-us/dnppcgen/http://msdn.microsoft.com/library/en-us/dnppcgen/html/eff_arch_sql_servr_ce_rep.asphtml/eff_arch_sql_servr_ce_rep.asp““Comparing Remote Data Access (RDA) and Merge Comparing Remote Data Access (RDA) and Merge Replication” in SQL 2005 BOLReplication” in SQL 2005 BOL

Page 32: Mobile

SummarySummarySQL Server 2005 Mobile Edition SQL Server 2005 Mobile Edition functionality is greatly enhanced for functionality is greatly enhanced for developersdevelopers

Integration with SQL Server 2005 Integration with SQL Server 2005 makes generation and maintenance makes generation and maintenance of SQL Mobile databases betterof SQL Mobile databases better

Integration with Visual Studio 2005 Integration with Visual Studio 2005 makes developing of SQL Mobile makes developing of SQL Mobile applications easier and fasterapplications easier and faster

Remote data access vs. merge Remote data access vs. merge replicationreplication

Page 33: Mobile

Heartland Developers Heartland Developers Conference ’05Conference ’05

October 13 – 14, Cedar Rapids, IAOctober 13 – 14, Cedar Rapids, IA

TWICE THE SIZE (days, sessions, TWICE THE SIZE (days, sessions, attendees, parties)attendees, parties)

Developer Pre-Party on the 12Developer Pre-Party on the 12thth and and Developer Jam on the 13Developer Jam on the 13thth

2 Keynotes, 18 Sessions, Developer 2 Keynotes, 18 Sessions, Developer LoungesLounges

2 Tracks: Center Stage / Behind the 2 Tracks: Center Stage / Behind the CurtainCurtain

Many door prizes including a top of Many door prizes including a top of the line Alienware Laptop!the line Alienware Laptop!

http://www.heartlandDC.comhttp://www.heartlandDC.com

Page 34: Mobile

© 2004 Microsoft Corporation. All rights reserved.© 2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.Content created by 3 Leaf SolutionsContent created by 3 Leaf Solutions

Page 35: Mobile