0

My app runs locally and stores its data in a sqlite database file. I need to ensure that when one instance of the application is running, the other instance can't write to the same database file.

If I worked with the database file not through the sqlite engine, I could open it for reading and writing and not close it, but how this can be done in the sqlite engine?

And how this can be done in sqlite provider in Entity Framework?

Alex A.
  • 422
  • 3
  • 12
  • Hello. Check if this is what you are looking for: https://stackoverflow.com/questions/13404061/how-can-i-lock-a-table-on-read-using-entity-framework – Kiril1512 Nov 16 '20 at 15:59
  • Check out this SO post: https://stackoverflow.com/questions/21886157/function-to-get-exclusive-lock-in-sqlite – LocEngineer Nov 16 '20 at 15:59
  • @Kiril1512б, I know that in sqlite, I can lock a table or row. But this is not exactly what I need in this case. I need to lock access to the entire database while my program is still running (until I gave the command to save data and release the database). – Alex A. Nov 16 '20 at 18:15
  • @LocEngineer , I tried using BEGIN EXCLUSIVE. Executed this command at the beginning (even outside of EF - just in a python script for test). However, this did not prevent another process (script) from dropping a table that could potentially be needed by the first one. And the point here is that as far as I understand, BEGIN EXCLUSIVE can create exclusive access only for the transaction, but not for the whole db session. – Alex A. Nov 16 '20 at 18:33

0 Answers0