Enable sharing in System.Data.Sqlite (.net)

I am looking for a way to enable shared cache mode when using the System.Data.SQLite shell for SQLite.

I looked at the source code for this project and see that it is open inside the assembly in UnsafeNativeMethods.cs as:

internal static extern SQLiteErrorCode sqlite3_enable_shared_cache( int enable); 

Unfortunately, I cannot get this method because it is internal.

Does anyone have a solution for this?


Answers were most appreciated. Thanks!

FYI, using the SQLiteConnectionStringBuilder API, enable the shared cache with:

 var builder = new SQLiteConnectionStringBuilder(); ... builder.Add("cache", "shared"); 
+5
source share
2 answers

SQLite uses PRAGMA statements to modify database operations. These statements are specific to SQLite. PRAGMA operators can be anything: from turning on foreign keys, changing circuit versions to setting shared cache parameters (a full list of pragma commands is available here ) With Pragma's statements, I know about two ways to execute them; 1) when creating a connection string or 2) Loaded as a command

1) During Instantiation

 new SQLiteConnection("Data Source=c:\mydb.db;Version=3;cache=shared"); 

2) A separate command Pragma statements can be executed as any normal database command sqliteConnection.Open ();

 var cmd = new SQLiteCommand("PRAGMA cache=shared",sqliteConnection); cmd.ExecuteNonQuery(); 

Another question worth looking at: Reading multiple SQLite SharedCache titles

+2
source

You can enable shared cache in the connection string:

 var connection = new SQLiteConnection("FullUri=file:mydb.sqlite?cache=shared"); 
+5
source

All Articles