One SQLiteConnection per thread?

I am using SQLite from system.data.sqlite.org

We need to access the database from many threads (for various reasons). I read a lot about the safe flow features in sqlite (the default synchronization mode is suitable for me).

I wonder if you can just open the connection to the stream. Is something like this possible? I really don't need race conditions (ask for something that has not yet been inserted). My only interest is that you can access data using one SQLiteConnection object for each thread.

+7
source share
2 answers

Yes. Actually, this is the correct way, since SQLite is not thread safe (by default. You can make it thread safe compiling with some option). And only to ensure its operation: SQLite is used on some small sites, so there is multithreading :)

Here's more information: http://www.sqlite.org/faq.html#q6

+4
source

Given that you use a separate connection for each thread, you should be fine.

From docs

Note that an instance of SQLiteConnection is not guaranteed to be thread safe. You should avoid using the same SQLiteConnection in multiple threads at the same time. It is recommended that you open a new connection to the stream and close it when the job is done.

+5
source

All Articles