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

淺唱寂寞╮ 提交于 2019-12-04 03:19:17

问题


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 ]


回答1:


This was a connection string issue.

File Mode=Read Write

solved the problem.




回答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.



来源:https://stackoverflow.com/questions/427888/why-do-i-receive-file-share-error-if-sql-compact-allows-multiple-connections

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!