0

Our application uses an SQLite database file to hold some data in it. The app opens the database in the file on startup, reads and writes to it, and closes it on exit.

Unfortunately, we can't forbid someone from running two copies of our app at once. If that happens, presumably there will be two copies of the app trying to read from and/or write to the file at the same time. I imagine this would not end well for the database file.

What can we do to avoid causing data loss for the user? Should we simply avoid opening the database if a second copy of the app is launched concurrently? Or is there something cleverer we can do?

Thanks.

1

2 Answers 2

2

Any sane database provider, including sqlite, will not corrupt your database if 2 people access it at the same time. Most will queue the requests if there's no way to run them in parallel.

Now what your app does with the data, that is your app's problem, but don't worry about the database itself.

Sign up to request clarification or add additional context in comments.

2 Comments

Given that SQLite is just based in a single file, are you sure that this true? Or does the DLL do some sort of black magic to ensure that even if two people use the file at once, it'll all be fine?
I am certain sqlite won't corrupt your database, yes. Keep in mind it is more than just a single file, you're accessing it through an api, and it will handle access synchronization for you.
2

Some info about sqlite concurrency: http://www.sqlite.org/lockingv3.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.