我在Android和iOS中使用库SQLite.Net-PCL,刚刚遇到错误。也许我误解了一些东西,但是SQLite文档指出:序列化。在序列化模式下,SQLite可以不受限制地被多个线程安全使用。但是,当我在多个线程上共享连接时,似乎出了点问题。我写了一个测试应用程序。见下文。通过“同时”插入,我得到了SQLite.Net.SQLiteException:Misuse。这是完整的例外:SQLite.Net.SQLiteException:SQLite.Net.PreparedSqlLiteInsertCommand.ExecuteNonQuery(System.Object []源)[0x0016b]在<8f2bb39aeff94a30a8628064be9c7efe>:0处的滥用在SQLite.Net.SQLiteConnection.Insert(System.Object obj,System.String ,System.Type objType)在SQLite.Net.SQLiteConnection.Insert(System.Object obj)在<8f2bb39aeff94a30a8628064be9c7efe>:0中的[0x000fc] [0x00012]在test.b.DisplayClass(System.System.0)上在<8f2bb39aeff94a30a8628064be9c7efe> = 0时。 /Users/dev/Documents/Xamarin/TestRepo/test/TestTask.cs:49中的对象aName)[0x00052]如果您随后查看数据库,它甚至看起来好像有重复的记录。所以我的问题是:串行化模式是否不设计为在多个线程中使用单个连接?还是SQLite库中的错误?用法(iOS示例): void HandleOnMessage(string msg) { UIApplication.SharedApplication.InvokeOnMainThread(() => Console.WriteLine(msg)); } void DoIt() { var platform = new SQLite.Net.Platform.XamarinIOS.SQLitePlatformIOS(); platform.SQLiteApi.Config(ConfigOption.Serialized); var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal); path = Path.Combine(path, "test.db"); TestTask.Init(platform, path, HandleOnMessage); TestTask.Run(); }附加信息:我在Android Simulator和Android Device中遇到相同的问题我正在使用Visual Studio for Mac 7.4.3(Build 10)我正在使用iOS 11.3的iPhoneX模拟器上进行调试
1 回答
- 1 回答
- 0 关注
- 207 浏览
添加回答
举报
0/150
提交
取消