Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL CE file sharing violation for multiple processes on local machine

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;") 
like image 205
Dennis Avatar asked Dec 09 '13 14:12

Dennis


1 Answers

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.

like image 138
Dour High Arch Avatar answered Nov 06 '22 06:11

Dour High Arch