[英]Can't open Sqlite database in read-only mode
I have a Sqlite database that I include with my MonoTouch app. 我有一个Sqlite数据库,我包含在我的MonoTouch应用程序中。 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: 所以我已经将连接字符串更改为包含'Read Only = True',但是当我调用Open()时,我收到以下错误:
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 ();
You found a bug in Mono.Data.Sqlite.dll
. 您在Mono.Data.Sqlite.dll
发现了一个错误。
The Create
flag is appended (by default) before the ReadOnly
flag is parsed and set. 在解析和设置ReadOnly
标志之前,会附加(默认情况下) Create
标志。 The resulting flag is invalid and sqlite reports an error. 结果标志无效, sqlite报告错误。
I will fix this for future releases (of Mono and MonoTouch...). 我会为将来的版本(Mono和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. 如果这阻止了你,那么请在http://bugzilla.xamarin.com上打开一个错误报告,我会将一个固定的程序集(带有替换现有程序的说明)附加到错误报告中。
你有没有尝试过?:
var _conn = new SqliteConnection("Data Source=db/sampleDb;mode=ro");
这对我有用(aspnet核心):
var _conn = new SqliteConnection("Data Source=db/sampleDb;mode=ReadOnly");
Your code is correct, I just tried it (not using MonoTouch) and it worked for me. 你的代码是正确的,我只是尝试过(不使用MonoTouch),它对我有用。
Do you have the latest version of System.Data.SQLite.dll
? 你有最新版本的System.Data.SQLite.dll
吗? If yes, then maybe it's a problem related to MonoTouch. 如果是,那么可能是与MonoTouch有关的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.