Cannot Open Sqlite Database Read Only

I have a Sqlite database that I include in my MonoTouch application. So far, it worked perfectly, but now I want to open it only in read-only mode, and not read-write.

So, I 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 what about all the information he gives.

Here is the code:

 var _conn = new SqliteConnection("Data Source=db/sampleDb;Read Only=True"); _conn.Open (); 
+6
source share
4 answers

You found an error in Mono.Data.Sqlite.dll .

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

I will fix this for future releases (Mono and MonoTouch ...). If this blocks you, open the error report http://bugzilla.xamarin.com and I will add the corrected assembly (with instructions for replacing the existing one) in the error report.

+7
source

You tried?:

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

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

Do you have the latest version of System.Data.SQLite.dll ? If so, this may be a MonoTouch related issue.

0
source

This worked for me (aspnet core):

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

Source: https://habr.com/ru/post/904307/


All Articles