[SQLite] File sharing violation

NoobCube

Member
Joined
Mar 2, 2014
Messages
12
Programming Experience
Beginner
Hello,
My C# application using Sqlite DB to store data.
As I know this db allows multiple read at the same time, but only one write at a time.

I want to run multiple instances of the same app and each one will read from the same db file.
and here is the error that I get:
There is a file sharing violation a different process might be using the file

error happens when one of the app instances trying to open connection while other app reading from db...

Help please! :concern:
 

wim sturkenboom

Well-known member
Joined
Aug 6, 2014
Messages
85
Location
Roodepoort, South Africa
Programming Experience
10+
If your DB is on a network, the below might be the issue.

From https://www.sqlite.org/faq.html#q5

SQLite uses reader/writer locks to control access to the database. (Under Win95/98/ME which lacks support for reader/writer locks, a probabilistic simulation is used instead.) But use caution: this locking mechanism might not work correctly if the database file is kept on an NFS filesystem. This is because fcntl() file locking is broken on many NFS implementations. You should avoid putting SQLite database files on NFS if multiple processes might try to access the file at the same time. On Windows, Microsoft's documentation says that locking may not work under FAT filesystems if you are not running the Share.exe daemon. People who have a lot of experience with Windows tell me that file locking of network files is very buggy and is not dependable. If what they say is true, sharing an SQLite database between two or more Windows machines might cause unexpected problems.
So I guess that in that case you're better of writing a small server app that your applications can connect to ;)

If your apps are all running on the same machine as the database, there should not be an issue (according to above).
 
Top Bottom