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 ]
This was a connection string issue.
File Mode=Read Write
solved the problem.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With