Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set threading mode in SQLite with Entity Framework?

I'm using SQLite with Entity Framework Core (RC1).

I read, that SQLite supports three different threading modes: Single-thread, Multi-thread and Serialized.

How do I set in run-time, which mode I want to use with my database?

like image 861
Tschareck Avatar asked Jun 23 '26 01:06

Tschareck


2 Answers

Microsoft.Data.Sqlite references the SQLitePCRaw.bundle_e_sqlite3 NuGet package. That package contains a version of SQLite that has been compiled with SQLITE_THREADSAFE=1 (Serialized). Microsoft.Data.Sqlite doesn't currently expose an API to change this, nor did System.Data.SQLite.

See also aspnet/EntityFramework#5466.

like image 69
bricelam Avatar answered Jun 26 '26 22:06

bricelam


It is accomplished by opening a database with the appropriate flags set. SQLITE_OPEN_NOMUTEX for multithread or SQLITE_OPEN_FULLMUTEX for serialized. It looks like flag setting is available through the C interface:

https://www.sqlite.org/c3ref/c_open_autoproxy.html

So if you aren't using the C interface directly, you are at the mercy of EF and whether they have decided to support flag setting on database open.

like image 39
andrew Avatar answered Jun 26 '26 20:06

andrew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!