Sameers Portal


Sameers BLOG

Skip Navigation Links.

Can I access SQL CE database on my Pocket PC FROM desktop

Posted On: 8/18/2008

Even though, SQL Server Management (for studio 2005) allows you to connect to an SQL Server CE database directly on mobile, but when you try to do that, it throws error saying that path is not valid.

I have been searching for this a lot here and there, but no answer. I also talked to peoples on forums, but everyone said that you need a third party tool to do this. Well, after a lot of research, I finally found that it is possible without any third party control/tool. You can do this using Microsoft SQL Server Management libraries. Here is how you can do that.

Create a new project (windows forms application) and add the reference of C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\Microsoft.SqlServerCe.Client.dll to your solution. Please note that you must have SQL Server management studio installed in order to find this dll. Once you have that, you are ready to connect to SQL Server CE database file on mobile device.

Use the following to open conneciton:

Dim conn AsNew Microsoft.SqlServerCe.Client.SqlCeConnection( "Data Source ='Mobile Device\My Documents\Database.sdf';")
conn.Open()
--Do your stuff here.
conn.Close();

Thats all! Now you can interact with SQL CE Database directly on your Pocket PC, without copying that to local disk.

P.S: I was just told by a person that you are not allowed to distribute this dll with your application, I am not sure about this, so if someone knows the licensing issue, please write here.

Sameers


Comments

Posted By Mike On 8/18/2008 3:10:07 PM
great! that is a good found. I beleive it will help me a lot. Thanks Sameers

Posted By ErikEJ On 8/19/2008 10:13:50 AM
Hi Sameers, great find, but please notice that the Dll is neither supported nor documented by Microsoft. See this thread from the SQL Compact MSDN Forum: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=124762&SiteID=1 Would be a nice addition to the SQL Compact toolkit if it was, though.

Posted By Sameers On 8/21/2008 3:17:45 PM
Thanks Erik. I spent a lot of time on finding this solution, I know this is not a perfect thing, BUT I found something inside the DLL (Microsoft.SqlServerCe.Client.dll), that is, it has an exe file in its resources, named tdsserver.exe, I think it copies that to mobile device and use that to transfer data between two platforms. So maybe, if tdsserver.exe functionality is exposed, one can write its own wrapper to connect to SQL CE on Pocket PC

Sameers

Posted By John Stanely On 8/21/2008 5:10:04 PM
Yes, this is actually nice finding. thanks Sameers for sharing it.

Posted By Prashanth On 2/6/2009 9:17:55 AM
Hi,
We also have similar problem. we are using the DLL (Microsoft.SqlServerCe.Client.dll), but can we distribute it with the application ?

Posted By Sameers On 2/13/2009 2:52:58 AM
No Prashanth, You can not distribute that with your application. However, if SQL Server 2005 is already installed there, you can use it.

Posted By mobile application software development On 9/24/2009 7:40:22 AM
Wow, I never knew that access SQL CE database on my Pocket PC. That's pretty interesting…

Posted By enterprise mobility solution On 9/24/2009 9:03:05 AM
Good post, but have you thought about access SQL CE database before?

Posted By j2me mobile application development On 10/3/2009 1:30:05 AM
Great post! I’ve been very interested in Can I access SQL CE database on my Pocket PC FROM desktop for a long time.

Post your comments

Your Name: (Required)
Email or HTTP address: (Optional)
Comments: