New to compact framework tutorials? Learn to write your first compact framework application here.
Zac Efron - Hairspray star and Mythbusters' Kari Byron at Celebrity Treat. Check out income and career information in Singapore.

Tuesday, January 03, 2006

- Create a SQL Mobile database (part 1)

I recently conducted a small poll and it turns out that SQL Mobile is the most requested topic (see ongoing voting results here). So in this tutorial, we will cover how to create a SQL Mobile database for the PDA or emulator.

Having seen the SQL Server Express (mentioned here), let's now look at SQL Mobile.

Being the successor of SQL Server CE 2.0, SQL Mobile is Microsoft's lightweight database server that has a small enough footprint (~1.5MB) to fit and run smoothly in a Pocket PC device. It is included in Visual Studio .NET 2005, so you don't have to install anything as a developer. For end users, SQL Mobile can be installed on the Pocket PC 2003, Windows Mobile 5.0, Smartphone 5.0 as well as Windows CE 5.0 platforms. Word has it that SQL Mobile will be pre-installed in the ROM of all new Windows Mobile devices, just like Compact Framework 2.0.

In terms of features, SQL Mobile offers transactional support, multi-user access, as well as synchronization and replication with back-end servers. In terms of competition, I'm not too sure if these few players are still fighting close: Sybase SQL Anywhere, Oracle Lite and IBM DB2 Everyplace.

Alright, let's dive in to create our very first SQL Mobile database.

  1. Start Visual Studio and create a new smart device project.
  2. Click Data in the menu and select "Add New Data Source..." to see the following dialog window.



  3. Select the Database icon (to indicate that you are creating a database) and click Next.
  4. In the next screen, click "New Connection..." to create a new database.
  5. In the the pop-up "Add Connection" window, click "Change..." to select a data source type. You should see the following:



  6. Select "Microsoft SQL Server Mobile Edition" as the Data Source and leave the Data provider as ".NET Framework Data Provider for SQL Server Mobile Edition". Click OK.
  7. Back at the "Add Connection" dialog, leave "My Computer" radiobutton selected, and then click "Create" to specify the filename of the SQL Mobile database. Enter "C:\FirstDB.sdf" for the filename and leave the other fields as they are (you can also specify the password here, but we leave it empty for convenience).



  8. Click OK. If prompted on the empty password, click Yes.
  9. You may now click "Test Connection" to check if the database is in order.
  10. Click OK. Back at the first dialog window, click Next, and click Yes to add the database file to your project. In the next screen, click Cancel as we are not using generated DataSets in this tutorial.
  11. You will notice that the FirstDB.sdf has been added to your project. Click on it and press F4 to check that its "Copy to Output Directory" property is "Copy if newer". This means that the file will be copied to the emulator if the emulator does not have a copy or have an older copy.
  12. Now, from the menu, click View-> Server Explorer. And in the Server Explorer pane, click the "Connect to Database" icon (2nd icon from the right; or move your mouse over each icon to see the tooltip).
  13. Click Browse and go to your project folder and select the FirstDB.sdf file. (Note that you can also create a database here, but care must be taken to add the created file to your project.)
  14. Test the connection and click OK.
  15. In the Server Explorer pane, expand the tree, right-click on Tables and select "Create Table". Enter the table name and create 2 columns for it, as shown below. Click on the image below to zoom in. (Note that the custid column has Identity set to true, so that this column's value for each record is auto-generated.)



  16. Click OK.
  17. Finally, run your program.
  18. There's nothing interesting in your form. However, open File Explorer and browse to the folder which contains the deployed files (at \Program Files\yourProjName). You should see a file with the name "FirstDB" there. The .sdf extension is not displayed. Click on this file to open it with Query Analyzer. Query Analyzer allows you to explore and manage SQL Mobile databases from within the PDA environment.
  19. In Query Analyzer, expand the tree under the Objects tab. You should see this:



  20. That's it! You have created a simple SQL Mobile database and transferred it to the emulator/device. Part 2, coming soon, will cover how to create a SQL Mobile database programmatically.
Categories: [Data Access_] Tags: [] [] []

27 Comments:

Blogger danchong said...

Here's a nice post from TECHQUIK with MSDN links on how to manually install SQL Mobile and Query Analyzer to a device (not via Visual Studio deployment).

1/04/2006  
Blogger dru said...

# In the the pop-up "Add Connection" window, click "Change..." to select a data source type. You should see the following:

# Select "Microsoft SQL Server Mobile Edition" as the Data Source and leave the Data provider as ".NET Framework Data Provider for SQL Server Mobile Edition". Click OK.

***
Microsoft SQL Server Mobile Edition isn't an option. I have installed the Mobile SDK. What am I missing?

Thanks
***

5/15/2006  
Blogger danchong said...

hi dru, I installed the Visual Studio 2005 Professional Edition and the Windows Mobile 5.0 SDK, and SQL Mobile was provided by default. In your case, maybe you need to install the SQL Mobile SDK by accessing the first link on this page.

Hope this helps. Please let me know if you still face the same problem.

5/15/2006  
Anonymous Anonymous said...

One of those crazy questions.. we are moving from Palm and etc... We are deploying our application to a Windows Pocket PC (CE 5.0 Framework 2.0) and some people seem to think SQL MOBILE would not be used on this device, but SQL CE... Am I wrong in saying we are using SQL MOBILE...

8/11/2006  
Blogger danchong said...

SQL Mobile is the latest incarnation of SQL CE. So for your case, you will be using SQL Mobile if you use MS latest tools (i.e. VS2005).

However, if you are still using the older tools or even CF1.0 (note: most OS's are backward compatible, part of MS strategy), then SQL CE it will be.

8/11/2006  
Anonymous Anonymous said...

hai..first of all I want to thank you for having this blog,
please can you tell me how to know the right connectionstring on the PDA for SQLMobile?

I tried this but didn't work
Data Source ='.\firstDB.sdf';

9/13/2006  
Blogger danchong said...

maybe you can try this:
\Program Files\yourProjName\firstDB.sdf

9/14/2006  
Anonymous Anonymous said...

I already tried it too, but didn't work
this is how I do it:

dim connStr = "Data source='.\firstDB.sdf'"

Dim connection As New SqlConnection(connstr)

connection.Open()

Dim adapter As SqlDataAdapter = New SqlDataAdapter(queryString, connection)

Dim mstmap As New DataSet
adapter.Fill(mstmap, "MasterMap")

9/14/2006  
Anonymous Anonymous said...

My mistake, silly me!!
I'm still using sqlConnection not SqlCeConnection and SQLCeDataAdapter

thanks danchong for your reply

9/14/2006  
Anonymous Anonymous said...

hi..need help here,
I sometime get error when syncronizing data at New Subscription Wizard, and sometime I dont.but right now i cant sync, this is me error messages :
"Synchronizing Data (Error)
Messages
A request to send data to the computer running IIS has failed. For more information, see HRESULT.
HRESULT 0x80070002 (28037)

The operation could not be completed."

I've turn off the firewall, turn off the antivirus, plug the LAN cable but still error.

And want to ask about SQL Mobile, When I choose the Merge, the uniqueidentifier will be add at my table right?what should I do at inserting query process, I cant just insert it with NULL value right?
After my subscription doing input data, is it my publications will be automatic updated?
I'm little lost here..need advise

9/18/2006  
Anonymous Anonymous said...

Edith said...

Hi, i am student and asked to finish homework on developing PDA application, because this is new to me and now seeking help from all of you...
I had followed the steps listed above and created the database successfully, however, how can i retrieve and display the data to the application which is developed?
Please give a helping hand and guide me, thanks a lot ~

by the way, it's a helpful blog, keep it up & thx so much ~

1/17/2007  
Anonymous Anonymous said...

How about a tutorial on taking an existing SQL Server instance and mirroring so-to-speak the schema in a SQL Server CE db?

1/26/2007  
Anonymous Anonymous said...

Well everything works good for sure but when I try to make a query I can not save it for some reason neither does there seem to be any way to make any use of the query I just created other then running it in the VS 2005 developing screen. Making it utterly useless. I have Visual Studio 2005, Sql server 2005 included and when I open sql server 2005 allso I can't connect to SQLMobile server it is no option there.

2/19/2007  
Anonymous Anonymous said...

I hear ya. I can't find the option to save my query for SQL Server 2005 Compact Edition in Visual Studio 2005 SP1.

Any help out there?

6/08/2007  
Anonymous Anonymous said...

If you have Compact Edition instead of Mobile Edition in Add Connection window leave Data Source as my Computer. In Connection properties press Create and continue with create of DB as described in article

5/05/2008  
Anonymous Anonymous said...

How do I change the maximum database size in the "Add connection" wizard?

5/12/2008  
Blogger macfly said...

Thank you for the simple, straight to the point tutorial. I had been looking all day to figure out how to store my data on a PDA. Now i will need to figure out how to handle synchronization/data mapping to SQL Server DBs.

You have made it happen, thanks a bunch. Maybe someday you could post on the 'synch' techniques.

Cheers,

Martin Provost
Montreal, Qc Canada

7/03/2008  
Anonymous Anonymous said...

how to synchronize sdf data to sql server DB? or to another spreadsheet like excel? does anyone know the tool for this synch?

9/14/2008  
Anonymous Anonymous said...

Hello

I am developing application for CN2 Intermec mobile computer and need to store some data in database. I made an SQL mobile database and tryed to make a query with full outer join. It doesn't work. When i try to run query builder report some toke error
Here is example of query:

SELECT OSRED.Inv_Str
FROM{ oj Pripop FULL OUTER JOIN OSRED ON Pripop.Inv_Str = OSRED.Inv_Str }

I tried other joins INNER JOIN don't work either. Only thing that works is:

SELECT OSRED.Inv_Str
FROM Pripop, OSRED
WHERE Pripop.Inv_Str = OSRED.Inv_Str

I just cant believe that there is SQL language that doesn't have joins :P

11/10/2008  
Anonymous Anonymous said...

(法新社a倫敦二B十WE四日電) 「情色二零零七」情趣產品大產自二十三日起在倫敦的成人網站肯辛頓奧林匹亞展覽館舉行,倫敦人擺脫對成人網站性的保守態度踴躍參觀,許多穿皮衣與塑膠緊身衣的好色之徒擠進這項世界規a片模最大的成人生活A片下載展,估計三天展期可吸引八萬多好奇民眾參觀。

活動計畫負責人米里根承諾:「要搞浪漫、誘惑人、玩虐待,你渴望的色情我們都有。」

他說:「時髦的設計與華麗女裝,從吊飾到束腹到真人大小的雕塑,是我們由今年展出的數千件情色產品精選出的一部分,參展產品還包括時尚服飾、貼身女用內在美、鞋子、珠寶、色情影片玩具、影片、藝術、圖書及遊戲,更不要說性成人電影av女優輔具及馬術裝備。」

參觀民眾遊覽a片兩百五十多個情色電影攤位情色電影,有性感服裝、玩具及情色食品,迎合各種品味。

大舞台上表演的是AV女優美國野蠻搖滾歌手瑪莉蓮曼情色森的前A片妻─全世界頭牌脫衣舞孃黛塔范提思,這是她今年在英國唯一一場表演。

以一九a片下載四零年代風格成人電影演出的黛塔色情范提思表演性感的天堂鳥、旋轉木馬及羽扇等舞蹈。

參展攤位有的av推廣情趣用品,有的AV成人影片開展示人成人影片體藝術和人體雕塑,也有情色藝術家工會成員提供建議。

2/28/2009  
Anonymous Anonymous said...

Try effiproz-cf database for compact framework. effiproz-cf is written entirely in C#. http://www.effiproz.com/product_cf.aspx

3/31/2010  
Anonymous Anonymous said...

An attractive and modern looking components for .NET Compact Framework are offered by Bee Mobile.
Their components also provide data binding which allows you to easily connect your data base with the component and display the data fast and comfortably to the screen of the mobile device.

Check their web site at http://beemobile4.net

11/18/2010  
Anonymous Anonymous said...

i am developing the smart device application on vs2008 and when creating new database it does not show "SQL Server Mobile Edition"
its showing me "Microsoft SQL Server Compact 3.5"
any idea??

11/22/2010  
Anonymous Anonymous said...

脚やせエステ北海道
脚やせエステ千葉
脚やせエステ長野
脚やせエステ京橋
脚やせエステ沖縄
脱毛 川口
脱毛 吉祥寺
脱毛 京都
脱毛 高知
フェイシャルエステ栃木
フェイシャルエステ銀座
フェイシャルエステ立川
フェイシャルエステ奈良
フェイシャルエステ高知
エステ体験 仙台
エステ体験 川崎
エステ体験 蒲田
エステ体験 滋賀
エステ体験 徳島
青森市 エステ
前橋 エステ
渋谷 エステ
東京都 エステ
静岡県 エステ
名古屋栄 エステ
枚方市 エステ
山口県 エステ
メンズエステ 北海道
メンズエステ 渋谷
メンズエステ 島根
フェイシャルエステ
エステ お試し
メンズエステ
婚活

6/23/2011  
Anonymous Your Escort Agency said...

Your Escort Agency offers exclusive and most beautiful London escort girls of various nationalities.

8/23/2011  
Anonymous London escorts said...

Bestescort4U more then ten years providing best London escorts companionship in the UK.

10/05/2011  
Anonymous Escorts London said...

Hot - Collection is a honest and confidential London escort agency which provides genuine London escorts girls for gentlemen of taste.

10/10/2011  

Post a Comment

<< Home