Xamarin - SQLite.SQLiteException:格式错误的数据库架构

时间:2017-04-10 08:34:28

标签: xamarin.android sqlite-net

我正在尝试在Xamarin.Android项目中为我的数据库设置密码,这是包含Sqlcipher

之后的代码示例

首次安装工作正常,但当我关闭应用并重新打开它时,应用程序崩溃并出现此错误

SQLite3.Prepare2
android.runtime.JavaProxyThrowable: SQLite.SQLiteException: malformed database schema (Items) - unrecognized token: "]"

我的示例代码

private async void CreateDb()
        {
            string requireFlag = SharedPreManager<string>.GetSingleton(this).RetrieveAccessKey(DSPPublicKeys.REQUIRE_ALTER_KEY, "true").ToString();
            //Creating database, if it doesn't already exist 
            if (!File.Exists(_dbPath))
            {
         await _logic.CreateDb(_dbPath);
            }
            else if (File.Exists(_dbPath) && DSPPublicKeys.REQUIRE_ALTER_Client && requireFlag.Equals("true"))
            {
                DeleteDb();
                await _logic.CreateDb(_dbPath);
                SharedPreManager<string>.GetSingleton(this).SaveAccessKey(DSPPublicKeys.REQUIRE_ALTER_KEY, "false");
            }
            if (db == null)
            {
        db = new SQLiteAsyncConnection(_dbPath);
            }
          // set password to database 
         var t = db.QueryAsync<int>("PRAGMA key=123456").Wait(-1);

        if (NetworkUtils.IsNetworkConnected(ApplicationContext))
             _logic.MigrateDataFromBackend(db);
        }

表格定义

[Table("Items")]
    public class Item 
    {
        [PrimaryKey , Column("ID")]
        public long ID { get; set; }
        [Column("TradeNameEn")]
        public string TradeNameEn { get; set; }
        [Column("TradeNameNative")]
        public string TradeNameNative { get; set; }
        [Column("GenericName")]
        public string GenericName { get; set; }
        [Column("TimeStamp")]
        public long TimeStamp { get; set; }
        [Column("BaseUnitPrice")]
        public decimal BaseUnitPrice { get; set; }


    }

任何人都可以指导我为什么会出现这个错误

0 个答案:

没有答案