Reputation: 3678
Referring to question How do I share a SQL Server CE database file (.sdf) for multiple processes?
According MSDN, SQL CE allows 256 concurrent connections to single database.
But even on the SAME machine, I facing sharing violation error when I open the same database BUT with 2 different process (a.exe & b.exe, code is the same). What seems to be the problem here?
I was using connection string
SqlCeConnection("Data Source=d:\test.sdf;Encrypt Database=True;Password=test;File Mode=read write;")
Upvotes: 5
Views: 3878
Reputation: 1853
In my case, the file was somehow locked. I was using TFS online and the sdf file was in locked/edit mode, although i had checked out the file and removed read-only flag from file attribute.
To fix it, i had to open tfs source control explorer and remove the lock.
Please make sure that the file is not locked.
Note: This is an old post but I am only adding this answer so that it could be helpful to someone facing this issue.
Upvotes: 0
Reputation: 21711
This is not the answer you want to hear, but you should never attempt to open an SQL CE file from multiple processes. Yeah, I know, SQL CE 4.0 allows multiple writers, and you think you'll never have multiple writers writing to the same record, but this is like thinking it's safe to juggle flaming chainsaws so long as you wear a blindfold.
SQL CE modifies changed bytes inside the live data file. You cannot reliably do this from multiple processes. You think you can, but you can't. Read the accepted answer to the question you quoted; use a service-oriented database like SQL Express.
Upvotes: 5