0

I am having continuous crashes in ios, when trying to access sqlite database. My application has background sync process where it tries to fetch the data and store it in sql database in device. Some how in IOS device randomly it crashes.

one of the log is:

SQLite.SQLiteException: Corrupt

SQLiteCommand.ExecuteNonQuery () /Users/vagrant/git/src/SQLite.cs:2334 SQLiteConnection.Execute (System.String query, System.Object[] args) /Users/vagrant/git/src/SQLite.cs:673 DataAccessBase.TruncateData (System.Boolean isSyncRestarted) /Users/yagnaios/Documents/Documents - Venu’s MacBook Pro/Dev_Latest/TCRMobile/TCRMobile/DataAccess/DataAccessBase.cs:93 Home+d__16.MoveNext () /Users/yagnaios/Documents/Documents - Venu’s MacBook Pro/Dev_Latest/TCRMobile/TCRMobile/Pages/Home.cs:307 ExceptionDispatchInfo.Throw () /Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.3/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152

The app works fine in android but it is serious problem in IOS because once the database is corrupt, we are unable to use the app.

Sai Sunkari
  • 179
  • 3
  • 27
  • Are you writing to the database from multiple threads at the same time? That's something that'll give you corrupt databases from time to time. – Lucas Zhang Sep 07 '18 at 07:35
  • Yes am accessing db from multiple threads, we have sync running every x minutes which makes few http calls and updates data in db. Probably same time UI is updating. We need this functionality in our app so does setting Sqlite mode to Serialized help solve this problem? – Sai Sunkari Sep 07 '18 at 16:53

1 Answers1

0

You need to configure the database to serialize its access to the file. Make make sure you're staying away from threads/tasks in your code, or make sure that only one thread at a time is trying to write to the database.

For more information you can access here

Lucas Zhang
  • 18,630
  • 3
  • 12
  • 22
  • But in my application, sometimes UI thread access db and at the same time background sync access db from multiple threads. Its difficult to stop sync process when ui thread or any other thread accessing database. so if i configure the database to serialize does my problem solves? – Sai Sunkari Sep 10 '18 at 22:04