Search code examples
c#sqlitewindows-phone-8windows-phone-8.1corruption

Windows Phone 8.1 corrupting SQLite Database


I have a Windows Phone 8 app that a few users on Windows Phone 8.1 have reported problems with. It seems the SQLite files are getting corrupted somehow.

The app includes the following project references:

  • SQLite for Windows Phone (SQLite.WP80, Version=3.8.5)
  • Sqlite

I'm using sqlite-net-wp8 3.8.5 by Peter Huene (via NuGet).

The app allows SQLite files to be downloaded to make large amounts of data available offline. The app only ever opens these apps in read-only mode as can be seem from the code snippet below. Both available SQLite database files are very large - 1.8 GB and 2.6 GB. Either one or both of these files might be downloaded by the user.

using (SQLiteConnection conn = new SQLiteConnection(_filePath, SQLiteOpenFlags.ReadOnly))
{
    SQLiteCommand cmd = new SQLiteCommand(conn);
    cmd.CommandText = "SELECT EXISTS(SELECT 1 FROM tiles WHERE z=" + zoomLevel.ToString() + " AND x=" + x.ToString() + " AND y=" + y.ToString() + " LIMIT 1);";
    canProvideMapTile = cmd.ExecuteScalar<bool>();
}

The error I'm seeing in the logs is:

SQLite.SQLiteException: file is encrypted or is not a database
at SQLite.SQLite3.Prepare2(Database db, String query)
at SQLite.SQLiteCommand.Prepare()
at SQLite.SQLiteCommand.ExecuteScalar[T]()

From the logs I can see 2 devices have experienced this issue. Both device ids start with "RM-941" so it looks like they're both Lumia 625's. Perhaps the issue is limited to this specific model of device, or perhaps it's just coincidence? Downloading the large files is optional and only used by a handful of users.

One of the users installed the app to the phones SD card so was able to retrieve the database file for me. Indeed when I tried to open the database file using SQLite Expert I was presented with a "file is encrypted or is not a database" message.

The file was exactly the same size as the uncorrupted original, but did appear different when I ran "comp" to compare the two files. Here's the comp output:

Compare error at OFFSET 0
file1 = DB
file2 = 53
Compare error at OFFSET 1
file1 = BD
file2 = 51
Compare error at OFFSET 2
file1 = 65
file2 = 4C
Compare error at OFFSET 3
file1 = 51
file2 = 69
Compare error at OFFSET 4
file1 = 45
file2 = 74
Compare error at OFFSET 5
file1 = BE
file2 = 65
Compare error at OFFSET 6
file1 = A7
file2 = 20
Compare error at OFFSET 7
file1 = 5E
file2 = 66
Compare error at OFFSET 8
file1 = 8A
file2 = 6F
Compare error at OFFSET 9
file1 = 4F
file2 = 72
10 mismatches - ending compare

Details provided by user:

Phone h/w is:

  • Lumia 625
  • Manufacturer: RM-941_[REMOVED]
  • Firmware rev: 3058.50000.1424.0003
  • Hardware rev: 3.0.0.0
  • Radio s/w ver: 3.2.28072.7
  • Chip SOC ver: 8930
  • Screen: 480x800

Phone o/s is:

  • List item
  • Windows 8.1 Cyan
  • Version: 8.10.12393.890

The user has tried uninstalling and re-installing the app, but the issue persists.

Any ideas what might be going on?


Solution

  • It seems that there was an issue with the phone that was resolved by doing a factory reset. Quoting from the user that resolved the issue:

    "Doing a factory reset on the 625 fixes the issue, which points directly to a flawed 8.0 to 8.1 upgrade process."