Make SQLite Threadsafe

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
mridulap2003
Posts: 1
Joined: Thu 04 Aug 2016 12:33

Make SQLite Threadsafe

Post by mridulap2003 » Thu 04 Aug 2016 12:48

Hi,

We are using LinqConnect with SQLite in our silverlight application. It works well. But our application has multiple threads which read from/write to the same database.

Recently one of our clients complained that none of their data is getting saved. On checking, we found that SQLite was throwing the Exception 'The disk image is malformed'.

Upon encountering this error, we checked the integrity (PRAGMA INTEGRITY_CONSTRAINT;) in databases of other clients. Most of the databases are showing some issues - examples:

Code: Select all

sqlite> pragma integrity_check;
wrong # of entries in index sqlite_autoindex_PendingInternetSyncPosts_1

sqlite> pragma integrity_check;
 in database main 
Main freelist: 1 of 1 pages missing from overflow list starting at 0
Page 5548 is never used
Page 5558 is never used
Page 5719 is never used
Page 5769 is never used
Page 5893 is never used
rowid 5201 missing from index sqlite_autoindex_PatientPayment_1
rowid 5202 missing from index sqlite_autoindex_PatientPayment_1
rowid 5203 missing from index sqlite_autoindex_PatientPayment_1
Although, not all of them are throwing the 'Disk image is malformed' exception.
I need to implement a solution to fix this. In order to do that, I am trying to understand why are such errors occurring.

1) Is this because of the multithreaded access to database?
2) If so, I checked on SQLIte's website, that if the library is built with the SQLITE THREADSAFE macro, it will be thread safe (https://www.sqlite.org/threadsafe.html). So, does LinqConnect build the SQLIte library with this macro? If not, how do I do this?

Thanks,
Mridula.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Make SQLite Threadsafe

Post by Shalex » Mon 08 Aug 2016 13:36

mridulap2003 wrote:1) Is this because of the multithreaded access to database?
1. We think that you are right.
mridulap2003 wrote:2) If so, I checked on SQLIte's website, that if the library is built with the SQLITE THREADSAFE macro, it will be thread safe (https://www.sqlite.org/threadsafe.html). So, does LinqConnect build the SQLIte library with this macro? If not, how do I do this?
2. LinqConnect for Silverlight contains the ready-to-use SQLite embedded database engine from C# SQLite project. There is no way to specify the SQLITE THREADSAFE macro in this case.

3. Please send us a small test project for reproducing the error in our environment.
In case of >2MB attachment, we recommend either using some file exchange server (send us the corresponding link) or uploading a test project to our FTP server (the credentials will be provided by email request).

Post Reply