Bug 2721 - Can't open Sqlite database in read-only mode
Summary: Can't open Sqlite database in read-only mode
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: Mono.Data.Sqlite ()
Version: 2.10.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-01-03 09:39 UTC by Matt Jones
Modified: 2012-01-04 10:26 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Updated Mono.Data.Sqlite.dll (165.50 KB, application/octet-stream)
2012-01-04 10:25 UTC, Sebastien Pouliot
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Matt Jones 2012-01-03 09:39:20 UTC
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 ();


This relates to a Stack Overflow item here: http://stackoverflow.com/questions/8602726/cant-open-sqlite-database-in-read-only-mode

The answer was:

"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."
Comment 1 Sebastien Pouliot 2012-01-04 10:25:33 UTC
Created attachment 1125 [details]
Updated Mono.Data.Sqlite.dll

This is already fixed (from stackoverflow) in 4b577de71a25729cbdf0f744154a7b746899aa3d
So it will be part of MonoTouch 5.2. 

In the mean time you can use the attached assembly (on top of MonoTouch 5.x) by doing the following:

1) backup your /Developer/MonoTouch/usr/lib/mono/2.1/Mono.Data.Sqlite.dll and /Developer/MonoTouch/usr/lib/mono/2.1/Mono.Data.Sqlite.dll.mdb files

2) copy the attached file to /Developer/MonoTouch/usr/lib/mono/2.1/Mono.Data.Sqlite.dll

3) remove the /Developer/MonoTouch/usr/lib/mono/2.1/Mono.Data.Sqlite.dll.mdb symbols (they won't match anymore)

4) clean, rebuild and test your application
Comment 2 Sebastien Pouliot 2012-01-04 10:26:46 UTC
Let me know if there are any issue with the updated assembly.