Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ();
like image 989
vlad259 Avatar asked Dec 22 '11 10:12

vlad259


People also ask

How do I fix a corrupted SQLite database?

The only possible manual method to recover a corrupt SQLite database is using the open-source DB Browser for SQL. DB Browser is an open-source utility that allows you to fix minor errors in the SQLite database files.

How do I Access SQLite database with ODBC driver?

Open your Microsoft Access database. Select the External Data tab in the ribbon. Expand the New Data Source drop-down and select From Other Sources, then select ODBC Dababase. In the Get External Data - ODBC Database dialog box, select Import the source data into a new table in the curent database, and click OK.


2 Answers

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.

like image 92
poupou Avatar answered Oct 03 '22 00:10

poupou


This worked for me (aspnet core):

var _conn = new SqliteConnection("Data Source=db/sampleDb;mode=ReadOnly");
like image 28
hugo Avatar answered Oct 02 '22 23:10

hugo