Archive for July, 2010

Start With SQL Compact Edition (SQL CE)

Hi Further on my previous article for introduction to SQLCE (Check it), i am going to walk you through to SQLCE with a very simple application.This sample will guide you from adding a local database to creating a connection and some CRUD operations.

Adding a SQLCE database to Project

  • Add a new Item to the project .

AddSQLCEDB_1

  • Select the DATA option and select  local Database option.Provide a database name and click OK

AddSQLCEDB

  • You can find the local Database as bellow.

AddSQLCEDB_3

  • You need to have a reference to the SqlServerce.dll .

AddSQLCEDB_Reference

  • To browse the Database , Right Click on Model.sdf and click Open.Then you will be able to get the table details.To add a new table Right click on Tables and click on Add table.In this case i have created 2 tables as shown in figure.

AddSQLCEDB_SDFExplorer

Creating a connection from C# project

The System.Data.SqlServerCe namespace is the .NET Compact Framework Data Provider for SQL Server CE.  WithSystem.Data.SqlServerCe, you can create and manage SQL Server Mobile databases on a smart device and also establish connections to SQL Server databases.

  1. public void Connect()
  2.  {
  3. 	 string FileName="Model.sdf";
  4. 	SqlCeConnection con=new SqlCeConnection(@"Data Source=|DataDirectory|\"+ filename 	+".sdf;Password=123"          );
  5. 	con.Open();
  6. }

Retrieving Data

The following code perform simple Data retrieval from the SDF file based on the sqlcecommand.

  1. private void RetriveData()
  2. {
  3. string FileName="Model.sdf";
  4. SqlCeConnection con = new SqlCeConnection(@"Data Source=|DataDirectory|\" + FileName + ".sdf;Password=123");
  5. con.Open();
  6. SqlCeCommand comm = new SqlCeCommand("Select * from EmployeeMaster", con );
  7. SqlCeDataAdapter sqlceda = new SqlCeDataAdapter(comm);
  8. DataSet dsData=new DataSet("EMPLOYEE");
  9. sqlceda.Fill(dsData);
  10. gvEmpMaster.DataSource = ds.Tables[0];
  11. }

Get the sample Application code

The sample application stimulate a typical windows based application using sql CE.This application consist of a wireframe database (model.sdf) which will be used to create other files and based on it the user can insert data and later retrieve it.

Sample Application Download

5 Comments

SQL Server CE (compact Edition)

Good news for small application developers , Microsoft released compact version of SQLSERVER (SQLCE 4.0 CTP1 ) for desktop ,web as well as for mobiles.This embedded database format is a huge relief from cumbersome and hectic installation of sql server .Although this was from long back still its reliability and features introduced in 4.0 CTP1 is awesome.I would like to introduce the some review and remarks on it in a very short manner.

Sql Server Compact Edition(SQLCE) is a embedded database for Mobile,Desktop and Asp.Net based projects.

For Whom :

  • If you are going to develop small/Mid level office application.
  • If you want hassle free installation of Database (Copy and Paste option)

What is the Latest Version :

Latest Version : 4.00 CTP1 Download

Last Release : 3.5 SP 2 Download

Some Facts -:

  • Supports Data up to 4 GB.
  • File based code free Database
  • Supports concurrent multiple connection from .
  • Runs in process of Application (Other MS sql Editions used to have separate services)
  • SQL CE databases reside in a single .sdf file.
  • The .sdf files / Database can be password protected as well as encrypted.
  • SQL CE databases are ACID-compliant. Like Microsoft SQL Server,
  • SQL CE supports transactions, referential integrity constraints, locking as well as multiple connections to the database store

Advantages

  • Very Small footprint(2 to 2.05 MB).
  • File based Database with enhanced security option.
  • All you need is Copying of binary to your installation path.
  • Easily Upgradeable to higher versions (MSSQL Express etc..)

Limitations

  • Doesn’t support Stored Procedures, also they don’t have plan for it. Go through the nice article from Steve.Lasker Read it.

Just have a look at the detailed comparison matrix with sqlExpress Edition.

Feature
SQL Server Compact Edition
SQL Server
Express Edition
Deployment/Installation Features
Installation size 1.7mb download size

1.8mb expanded on disk

53.8mb download size

~197mb expanded on disk

ClickOnce deployment clip_image002 clip_image002[1]
Privately installed, embedded, with the application clip_image002[2] clip_image004
Non-admin installation option clip_image002[3] clip_image004[1]
Runs on Windows Mobile platform clip_image002[4] clip_image004[2]
Installed centrally with an MSI clip_image002[5] clip_image002[6]
Runs in-process with application clip_image002[7] clip_image004[3]
64-bit support clip_image002[8] clip_image002[9] Windows on Windows (WOW)
Runs as a service clip_image004[4] In process with the application clip_image002[10] N + 1
Data file features
File format Single file Multiple files
Data file storage on a network share clip_image002[11] clip_image004[5]
Support for different file extensions clip_image002[12] clip_image004[6]
Database size support 4GB 4GB
XML storage clip_image002[13] stored as nText clip_image002[14]
Code free, document safe, file format clip_image002[15] clip_image004[7]
Programmability
Transact-SQL
Common Query Features
clip_image002[16] clip_image002[17]
Procedural T-SQL

Select Case, If, features

clip_image004[8] clip_image002[18]
Remote Data Access (RDA) clip_image002[19] clip_image004[9]
ADO.NET Sync Framework clip_image002[20] clip_image004[10] Planed support with a future version
Subscriber for merge replication clip_image002[21] clip_image002[22]
Simple transactions clip_image002[23] clip_image002[24]
Distributed transactions clip_image004[11] clip_image002[25]
Native XML, XQuery/QPath clip_image004[12] clip_image002[26]
Stored procedures, views, triggers clip_image004[13] clip_image002[27]
Role-based security clip_image004[14] clip_image002[28]
Number of concurrent connections 256 Unlimited

, , ,

Leave a comment

Hi World ..

Hi all , this is my first blog after a long persue from my friends .It is always good to start late instead of not doing it.Ok my self Manas as you can find from domain name , i  am working in MNC , India as Technology Analyst and loves dancing.

Before i took up blogging i asked my self so many time times  “Why should i blog” .

As i got the answers after a lot of  in fight  with my consensus i want to share with you. As a human and as a engineer you need to improve and you need to excel in what ever you do and this improvement can be achieved if you analyse the work you have done and the experience you learned. I would like to share one quote :

“If you re-read your work, you can avoid a great deal of repetition and can achieve  improvement in future endeavor ”

So thats it 🙂 now i am ready to share it with me as well as  all of you .

I am going to write about my work experience related to Technology , life , business and what ever i feel i need to share with all.Of course i need you feed back and one line comment that will help me to do better .

Keep Reading .

Leave a comment

Design a site like this with WordPress.com
Get started