Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serealized mode in System.Data.SQLite for .NET

I am working on a .NET application that uses the SQLite. As per SQLite documentation, it supports multi-threading and can be used in one of following 3 modes

  1. Single-thread. In this mode, all mutexes are disabled and SQLite is unsafe to use in more than a single thread at once.
  2. Multi-thread. In this mode, SQLite can be safely used by multiple threads provided that no single database connection is used simultaneously in two or more threads.
  3. Serialized. In serialized mode, SQLite can be safely used by multiple threads with no restriction.

As per these modes, I am trying to use the Serialized where I am sharing the Single connection across multiple Tasks. But I get the error as "Operation is not valid due to the current state of the object."

I guess this is due to the sharing of single connection across tasks. But As per the Serialized mode I should be able to share the connection without doing any explicit locking or mutex implementation. Can any one please guide me how I can use the Serialized mode in .net application ? Does it requires connection string to be mentioned in certain way ?

Thanks in Advance !

like image 292
D Deshmane Avatar asked Nov 09 '22 03:11

D Deshmane


1 Answers

Serialized is the default mode. Do not close open connection again instead yse the same single connection every where without need of closing it. SQLite will take care of rest. Hope this helps.

like image 175
D Deshmane Avatar answered Nov 14 '22 23:11

D Deshmane