Brendan
Brendan

Reputation: 19353

How to use a read only database in windows phone?

I have followed this article on MSDN which clearly describes how to create a database using a helper application and then load it into the main application as Content. If the database is read only (which mine is), the article describes how it does not need to be loaded into isolated storage.

However after doing this and performing read-only queries on the database (Where, Select etc.), I get the following exception

The database is opened with a read-only connection. Can't perform post-initialization operations like re-building indexes and upgrading public tracking. Please re-open with a read-write connection.

This implies that the database always needs write access. How then do I use the database in read only mode as suggested by the article?

Here are the queries I am running,

IQueryable dataQuery = null;

// This line inside a switch statement which picks a particular table of clothing
dataQuery = this.clothingDB.DressSizes;

var dataBySize = dataQuery.Cast<IClothing>().Where(q => q.Size == size);
foreach (Retailer retailer in dataBySize.Select(ds => ds.Retailer).Distinct()) {
    /// ... Do something
}

Upvotes: 2

Views: 332

Answers (1)

ErikEJ
ErikEJ

Reputation: 41769

Something locale or OS wise has happened on the desktop, that now requires indexes to be rebuilt on the device. Workaround is to copy once (during Development only) the database file to isolated storage, open the database context to allow an index rebuild, extract the file from isolated storage, and including the updated (rebuilt) file as content, and then from there, you can open read-only.

Upvotes: 3

Related Questions