Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is SQLite.Net thread-safe?

I'm asking about the .Net implementation - System.Data.SQLite. Are there guidelines to using it in a thread-safe manner?

I know SQLite itself can be compiled with or without thread safety - but how was System.Data.SQLite compiled?

like image 811
ripper234 Avatar asked May 19 '09 21:05

ripper234


1 Answers

It is not thread-safe, so you cannot share connection objects or similar across threads.

The thread bugfixes mentioned in the readme file has to do with multiple threads using multiple connections (ie. one each) to the same file, and what kind of problems or race conditions that might produce.

For instance, the thread race condition mentioned for BEGIN and BEGIN IMMEDIATE had the unfortunate effect that even though a thread issued a BEGIN, another thread that issued a BEGIN afterwards could still end up owning the database before the first one did. These types of situations have been fixed.

But database connections (oracle, sqlite, ms sql server) in .NET are not thread-safe, nor are the surrounding objects.

like image 144
Lasse V. Karlsen Avatar answered Sep 18 '22 00:09

Lasse V. Karlsen