We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


How to access a SQL Compact 3.5 database on a device from the desktop (c#)

Medium Priority
Last Modified: 2013-11-17
I have an existing device (Windows Mobile) application that uses a SQL Compact database and works well.
I need to build a desktop application that can read and update the database (SDF file) while it is on the device.  I don't want to have to install SQL replication etc.
Since I can see the device folders when I have an ActiveSync session, I'm guessing there might be a way to use the files too.

How would I construct a connection string that could be used by a desktop client but point to the device file?

Can anyone help?
Watch Question


The link referred to explains the details of the connection string, but does not clarify how to specify the path to a file located on the device while running on the desktop.

The link tells you how to specify the location of the SDF file. It reads: "...Often times the .SDF database is not running in the current directory so it becomes necessary to programatically set the path to the SDF file.
So to specify the path you just need to do
...Data Source=myPath\myData.sdf ...


So do you know how to specify the path for a file on the device?  My device is called nab but
\\nab\MyDocuments does not work.

it should be
Data Source=nab\MyDocuments\myData.sdf  


Sadly that does not work.  I get this error on the connection.Open with the code shown below:
The path is not valid. Check the directory for the database

SqlCeConnection connection = new SqlCeConnection(@"DataSource=Nab\Storage Card\My Documents\MyDatabase.sdf");

Open in new window

Sorry Missed one "\". Also is "Data Source", not Datasource. Try like this:

SqlCeConnection conn = new SqlCeConnection("Data Source= \Nab\Storage Card\My Documents\MyDatabase.sdf");

Open in new window

Sorry you say that Nab is your device?
Then try this:

SqlCeConnection conn = new SqlCeConnection("Data Source= Nab\Storage Card\My Documents\MyDatabase.sdf");
SqlCeConnection conn = new SqlCeConnection("Data Source= \Storage Card\My Documents\MyDatabase.sdf");

Open in new window


I've tried all these combinations.  The problem is that the device file system is only available on the desktop via ActiveSync.
Clearly the Explorer window must be ActiveSync "aware" in order to allow me to browse the file system on my device, but it I try to browse by typint the path into the Start\Run dialog (as I might if I wanted to browse a network drive) it is not aware of my device (nab).
SQL Management Studio 2008 allows me to administer an SDF database file physically located on my device, so it must be possible to connect to it, but it is certainly not obvious how to do it.
Hmm, yeah. Using database on device from desktop application: that wont work because theres no way to reference database on device in desktop application; device is not mapped as desktop file system. Active Sync explorer extension simply fakes it. Visual Studio does that via special remote provider which is not public. If you want to access database on device then copy it to local file system (e.g. using RAPI), access it, and then copy it back to device.
Please take a look at this link:

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Thanks for all your assistance.
I think I may have to take the RAPI concept, although that is a bit clunky, especiallly with large files.
The Primeworks product looks like it does provide a solution so at least I know it is possible.
The licensing for SQL Compact does now allow use on the desktop - previous editions of SQL Mobile did not allow this.

You are welcome.
If you think I have helped please accept one of the comments as the answer, if not, just ask for the question to be deleted.


Unfortunately there does not appear to be a "solution" to my request, but the responses do suggest an appripriate workaround.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.