简体   繁体   中英

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 !

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM