Simple multi-user database solution

Ben Mc picture Ben Mc · Dec 6, 2009 · Viewed 25.2k times · Source

I've written a Windows desktop application that works with Sqlite very nicely. It was a single user app, and the database sits right on the machine where the app runs.

However, the application has grown, and now multiple users should be able to run the app and connect to one shared database.

I'd like to just be able to share the sqlite file on a network drive, but that would obviously result in corrupted data unless someone has any ideas.

I guess I could require the install of a database server, but a commercial MySQL license doesn't make sense, PostgreSQL is different enough that I'd have to rewrite a lot of my application. I haven't worked with Firebird at all, so I'm not sure if that's a good solution or not.

Are there any Sqlite database servers that can be installed that handle the incoming transactions on the Sqlite database file?

If I require the client to download and install MySQL on their own, do I have to have a commercial license?

Any suggestions or direction would be great, thank you.

Answer

James Kolpack picture James Kolpack · Dec 6, 2009

You may be able to use the Sqlite file on a shared network drive as you described, depending on the underlying filesystem:

http://www.sqlite.org/faq.html#q5

Multiple processes can have the same database open at the same time. Multiple processes can be doing a SELECT at the same time. But only one process can be making changes to the database at any moment in time, however.

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.