Your SlideShare is downloading. ×
Using SQL Local Database in Mobile Applications
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Using SQL Local Database in Mobile Applications

3,538
views

Published on

Published in: Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,538
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
55
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Using SQL Local Database inMobile ApplicationsMicrosoft SQL Server Compact (SQL CE) is acompact relational database produced by Microsoftfor applications that run on mobile devices anddesktops.With Windows Phone OS you can store relationaldata in a local database.
  • 2. About me  Mihail Mateev is a Senior Technical Evangelist, Team Lead at Infragistics Inc.  Mihail worked in various areas related to technology Microsoft: Silverlight, WPF, Windows Phone 7, Visual Studio LightSwitch, WCF RIA Services, ASP.Net MVC, Windows Metro Applications, MS SQL Server and Windows Azure2 |
  • 3. Agenda  Windows Phone  Windows Phone Mango Local Database(SQL CE)  Local Database Maintenance  Creating the Database  Database Queries with LINQ  Inserting Data  Updating Data  Deleting Data  Local Database Tools  SQL Compact Code Generator  CompactView  Isolated Storage Explorer3 |
  • 4. Windows Phone Platform  Goals  Simple End User Personalization  Enable Cloud Experiences  Help Developers be Profitable4 |
  • 5. Windows Phone Application Platforms  Silverlight  XNA  Vector XAML Graphics  Fast 3D Graphics  Rich Media Engine  Rich Video  2D Sprites  Visual Studio Good Tooling Tooling5 |
  • 6. Local Database for Windows Phone  With Windows Phone OS 7.1, you can store relational data in a local database that resides in your application’s isolated storage container.6 |
  • 7. Local Database for Windows Phone  Good to know  Isolated storage is used to store database files  LINQ to SQL is used as the ORM engine  LINQ is used to query data  Only System.Data.Linq assembly must be added to the project7 |
  • 8. Local Database for Windows Phone  Limitations  ADO.NET objects are not supported  Skip() and Take() require an ordered list and constant types  Only Microsoft SQL CE data types are supported  BinaryFormatter is not supported by default  ExcecuteCommand is not supported – NO T- SQL, NO DML statement, NO DDL8 |
  • 9. Local Database vs. SQL Server  A local database runs in the Windows Phone application’s process. Unlike a client-server database such as Microsoft SQL Server, it does not run continuously as a background service.  A local database can be accessed only by the corresponding Windows Phone application. Because the database file resides in isolated storage, no other applications can access that data.  A local database can be accessed only with LINQ to SQL; Transact-SQL is not supported.9 |
  • 10. Local Database Maintenance  Creating the Database  Database Queries with LINQ  Inserting Data  Updating Data  Deleting Data10 |
  • 11. Local Database(SQL CE): Connection Strings  A special format of private const string ConnectionString = @"isostore:/CountryDB.sdf"; the connection string public MainPage() must be used like for { example: InitializeComponent();  "Data using (CountryDataContext context = new Source=isostore:/DIRE CountryDataContext(ConnectionString)) { CTORY/FILE.sdf" if (!context.DatabaseExists()) { // create database if it does not exist context.CreateDatabase(); } } }11 |
  • 12. Data Context  It inherits from the "System.Data.Linq.DataContext" class  The data context constructor must call the base(connectionString) constructor  The data context exposes the tables from the database through properties of type Table<TEntity>. The Table class implements IQueriable<TEntity> and enables you to write LINQ queries against the database.12 |
  • 13. Creating a Local Database using (CountryDataContext  After you create the context = new DataContext CountryDataContext(ConnectionS tring)) object, you can create { the local database if (!context.DatabaseExists()) and perform a { number of additional // create database if it does not exist database operations. context.CreateDatabase(); } }13 |
  • 14. Creating a Local Database  CountryDataContext is implemented in the following way:14 |
  • 15. Database Queries with LINQ15 |
  • 16. Inserting Data16 |
  • 17. Inserting Data17 |
  • 18. Updating Data18 |
  • 19. Deleting Data19 |
  • 20. Local Database Tools  SQL Compact Code Generator  CompactView  Isolated Storage Explorer20 |
  • 21. SQL Server Compact Toolbox SQL Server Compact Toolbox is a Visual Studio 2010 Pro or higher add-in (for 3.5/4.0) and standalone app (for 4.0), that adds scripting, import, export, mig rate, rename, run script, manage replication and more to your SQL Server Compact Data Connections in VS Server http://sqlcetoolbox.codeplex.com/ Explorer.21 |
  • 22. CompactView  CompactView is a viewer for Microsoft® SQL Server® Compact Edition (SQLCE) database files (*.sdf).  CompactView can open database files of versions 3.1, 3.5 and 4.0. http://sourceforge.net/p/compactview/home/Home/22 |
  • 23. Isolated Storage Explorer  Add-In for Visual  Import data from Studio 2010 to Isolated Storage import, export or  Export data to modify data from the Isolated Storage isolated storage of the  automatic retrieval of phone or the emulator the target (emulator / Windows Phone phone) and the identifier of the current project23 |
  • 24. Isolated Storage Explorer http://istool.codeplex.com/24 |
  • 25. DEMO
  • 26. QUESTIONS Q&A26 |
  • 27. Sponsors