vlad259
vlad259

Reputation: 1236

Can't open Sqlite database in read-only mode

I have a Sqlite database that I include with my MonoTouch app. It has worked fine for me so far, but now I want to open it in read-only mode rather than read-write.

So I have changed the connection string to include 'Read Only=True', but when I call Open(), I get the following error:

Library used incorrectly (at Mono.Data.Sqlite3.Open)

If I dig into the exception it shows

_errorCode = Misuse

and that's about all the info it gives.

Here's the code:

var _conn = new SqliteConnection("Data Source=db/sampleDb;Read Only=True");
_conn.Open ();

Upvotes: 7

Views: 8362

Answers (4)

hugo
hugo

Reputation: 1849

This worked for me (aspnet core):

var _conn = new SqliteConnection("Data Source=db/sampleDb;mode=ReadOnly");

Upvotes: 2

poupou
poupou

Reputation: 43553

You found a bug in Mono.Data.Sqlite.dll.

The Create flag is appended (by default) before the ReadOnly flag is parsed and set. The resulting flag is invalid and sqlite reports an error.

I will fix this for future releases (of Mono and MonoTouch...). If this blocks you then please open a bug report on http://bugzilla.xamarin.com and I'll attach a fixed assembly (with instructions to replace the existing one) to the bug report.

Upvotes: 10

ken2k
ken2k

Reputation: 48985

Your code is correct, I just tried it (not using MonoTouch) and it worked for me.

Do you have the latest version of System.Data.SQLite.dll? If yes, then maybe it's a problem related to MonoTouch.

Upvotes: 0

IanNorton
IanNorton

Reputation: 7282

Have you tried?:

var _conn = new SqliteConnection("Data Source=db/sampleDb;mode=ro");

Upvotes: 1

Related Questions