SQLite Forum

Add option for a process exclusive mode to open files on Windows
Originally posted to https://system.data.sqlite.org/index.html/tktview/0b91277bb4e13c7c68bd

When making calls to the Win32 CreateFile() function, SQLite appears to always set the file sharing parameter dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE which allows the file to be opened for shared access across processes.  CreateFile() must be called with a dwShareMode = 0 in order to open the file in a true process exclusive access mode. See https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files for full details.

A side effect of this behavior is even when SQLite is configured for EXCLUSIVE WAL mode, users are still able to copy open SQLite database files on Windows using Explorer or other means which can result in corrupt copies that befuddle end users.

To avoid this for our use cases, we're currently having to rebuild our own custom version of SQLite which allows us to force dwShareMode = 0.  We're reaching out and see if there would be any appetite to add an option to allow for a process exclusive file access mode in the upstream SQLite?