Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I receive file share error if Sql Compact allows multiple connections?

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 ]

like image 252
Serhat Ozgel Avatar asked Jan 09 '09 12:01

Serhat Ozgel


2 Answers

This was a connection string issue.

File Mode=Read Write

solved the problem.

like image 128
Serhat Ozgel Avatar answered Oct 05 '22 06:10

Serhat Ozgel


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.

like image 23
AechoLiu Avatar answered Oct 05 '22 07:10

AechoLiu