views:

444

answers:

1

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?

+4  A: 

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.

Lasse V. Karlsen
To add a small amount to the above - the ADO.NET spec does NOT recommend or require they be thread safe. You are supposed to use one connection per thread - that is the design of ADO.NET.
Jason Short