6

Here, it is said that Sql Server Compact allows up to 256 connections.

But when I try to open 2 connections, I receive a file sharing error. How can I solve this?

SqlCeConnection c1 = new SqlCeConnection("Data Source=testDB.sdf;Encrypt Database=True;Password=test;File Mode=shared read;Persist Security Info=False;");
SqlCeConnection c2 = new SqlCeConnection("Data Source=testDB.sdf;Encrypt Database=True;Password=test;File Mode=shared read;Persist Security Info=False;");
c1.Open();
c2.Open(); // throws SqlCeException
c1.Close();
c2.Close();

There is a file sharing violation. A different process might be using the file. [ testDB.sdf ]

Serhat Ozgel
  • 23,496
  • 29
  • 102
  • 138

2 Answers2

9

This was a connection string issue.

File Mode=Read Write

solved the problem.

Serhat Ozgel
  • 23,496
  • 29
  • 102
  • 138
  • 1
    I just had this same problem. Stupid mistake really... thanks for putting me right. – Eddie Nov 03 '11 at 14:17
  • I got the same error using SQL compact 4.0 for a small website with concurrent users. This suggestion did not resolve my problem. – John Melville Jan 25 '12 at 05:58
2

When survey this problem, I find some resources and this post. Maybe someone will need it, so I leave what I find here.

According the MSDN said, if no File Mode assigned, it will use Read Write by default.

And, if need to open a Read Only db, this post said two parameters should be assigned. One is File Mode, and one is Temp Path.

Community
  • 1
  • 1
AechoLiu
  • 17,522
  • 9
  • 100
  • 118