• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1230
  • Last Modified:

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

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?
0
rightfile
Asked:
rightfile
  • 7
  • 6
1 Solution
 
ralmadaCommented:
0
 
rightfileAuthor Commented:
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.
0
 
ralmadaCommented:
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 ...
 
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rightfileAuthor Commented:
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.
0
 
ralmadaCommented:
it should be
Data Source=nab\MyDocuments\myData.sdf  
0
 
rightfileAuthor Commented:
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");
connection.Open();

Open in new window

0
 
ralmadaCommented:
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");
conn.Open();

Open in new window

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

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

Open in new window

0
 
rightfileAuthor Commented:
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.
0
 
ralmadaCommented:
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:
http://social.msdn.microsoft.com/forums/en-US/sqlce/thread/68511c18-31e9-479c-a5ca-8674f0a0e288/ 
0
 
rightfileAuthor Commented:
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.
 
0
 
ralmadaCommented:
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.
Regards,
ralmada
0
 
rightfileAuthor Commented:
Unfortunately there does not appear to be a "solution" to my request, but the responses do suggest an appripriate workaround.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now