views:

913

answers:

4

Im trying to access a Sql CE 2005 database on a windows mobile device from two different applciations.

From the information I found online it should work but when I open the second connection I get a file sharing violation error

"There is a file sharing violation. A different process might be using the file. [ \\\Program Files\xx\DB.sdf ]"

Any ideas on what I'm doing wrong??

A: 

Is it same process is using multiple threads to access this sdf file, or only one thread. When it says some other "PROCESS" is accessing the file, what is it? Is it VS, or something else. I think you can use the remote process viewer to see which processes in the device are using this SDF file. If you could see seperately which handles are for which processes in a device, that would be great. Even otherwise, just try to delete the sdf file (or move/rename it), after killing some processes on the desktop. That might tell you what is the offending process.

sivaramakrishna
No they're two separate applications. Both are trying to open the same database. One opens the connection and when the second one tries to open it it gives the file sharing violation error. Im using this connection string to connect.conn = new SqlCeConnection("Data Source=\\\Program Files\xx\DB.sdf");
Marcom
+2  A: 

SQL Compact does support multiple connections to the database, even back with version 3.0. How is the first process opening the database? For example, the mobile Query Analyzer from 3.0 and 3.1 did open the database exclusively, effectively locking it from any other process.

ctacke
both application use the same connection string SqlCeConnection conn = new SqlCeConnection("Data Source=\\\Program Files\xx\DB.sdf");conn.Open();the first application that opens the db withtout probs. the second one throws the error.
Marcom
I can tell you that in certain cases, it doesn't matter that SQL CE supports multiple connections. You can still get the sharing violation error.For instance, on the desktop if the SDF file is on the user's local machine, multiple processes/connections can be made to it. Place that SDF file on a network share, and it's a different story. Only 1 process can access it at a time.I wonder if its the same situation when opening on a mobile device.
CBono
It's well documented that it won't work on a network share (http://www.pluralsight.com/community/blogs/jimw/archive/2007/02/19/46151.aspx). It does work fine on a device - I have a few solutions that require multiple processes using the same database file.
ctacke
so I am doing something wrong. Do I need to set some extra parameters in the connection string?
Marcom
+1  A: 

The problem was the connection string .....

"Data Source=\\\Program Files\xx\DB.sdf" apparently opens the database as a single user

using

"Data Source=Program Files\xx\DB.sdf" opens the database normally...

Marcom
A: 

SQLCE 4 Community Technology Preview is out. It supports multi user scenario and access from multiple threads of the same process.

It does not suffer from the same problems as SQlCE 3.5. Works well on 256 connections.

Merc