7
votes

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 ();
4

4 Answers

9
votes

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.

2
votes

This worked for me (aspnet core):

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

Have you tried?:

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

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.