标签: sqlite-net-pcl

sqlite-net-pcl SqliteAsyncConnection.CreateTableAsync<T> 抛出 System.MissingMethodException

我正在尝试使用最新版本的 sqlite-net-pcl nuget 包创建一个表

var db = new SQLiteAsyncConnection("data.db");
await db.CreateTableAsync<Site>();
Run Code Online (Sandbox Code Playgroud)

CreateTableAsync 调用引发以下异常:

System.MissingMethodException: '方法未找到:'System.String SQLitePCL.raw.sqlite3_column_name(SQLitePCL.sqlite3_stmt, Int32)'。'

这是站点类

public class Site
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    public String Name;
    public String PriceCssSelector;
    public String URLRegex;

    public Site()
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试降级到 sqlite-net-pcl 包的最新稳定版本。

c# sqlite-net sqlite-net-pcl

6
推荐指数
2
解决办法
2785
查看次数

无法加载文件或程序集 'e_sqlite3

当我调试 UWP 项目时,出现以下错误:

System.IO.FileNotFoundException: '无法加载文件或程序集 'e_sqlite3,Culture=neutral,PublicKeyToken=null'。该系统找不到指定的文件。'

错误发生在这一行: Xamarin.Forms.Forms.Init(e);

从以下代码块:

protected override void OnLaunched(LaunchActivatedEventArgs e)
{
    Frame rootFrame = Window.Current.Content as Frame;

    // Do not repeat app initialization when the Window already has content,
    // just ensure that the window is active
    if (rootFrame == null)
    {
        // Create a Frame to act as the navigation context and navigate to the first page
        rootFrame = new Frame();

        rootFrame.NavigationFailed += OnNavigationFailed;

        Xamarin.Forms.Forms.Init(e);

        if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
        {
            //TODO: Load state from previously …
Run Code Online (Sandbox Code Playgroud)

c# xamarin.forms xamarin.uwp sqlite-net-pcl

5
推荐指数
0
解决办法
1079
查看次数

SQLite似乎不再可以在Xamarin Android上使用

我们有一个Xamarin.Forms项目,需要使用sqlite本地数据库来存储日期。来自不同PC的不同开发人员使用EF Core的sqlite库进行设置(vs 2019)。最初,它与Database.EnsureCreated()功能一起使用,后来与ef core的迁移一起使用。一切都进行了一个多月。

上周,由于sqlite出现错误,Android应用突然无法在任何人的PC上启动。它显示以下错误:

致命信号11(SIGSEGV),代码1(SEGV_MAPERR)

我花了一段时间尝试各种修复和回滚,认为这是代码的问题。其中包括以下内容:

  1. 删除的obj和bin文件夹,清理并重建以下所有步骤。
  2. 将ef的版本降级到2.2.3(我们开始使用的版本)
  3. 回滚到git提交最多一周
  4. 升级了ef core的依赖项版本
  5. 删除了过去的一些迁移
  6. 将Xamarin表格降级为3.6.x

在尝试了上述修复程序和其他修复程序之后,终于在上周五(在所有PC上)升级了Java和android SDK的版本。此修复程序奏效后,当天一切都会顺利进行。在星期二,问题再次出现(没有库更新或代码更改)。更深入地了解EF Cores日志记录表明,它在尝试连接到数据库时崩溃。

该问题可以在android设备上复制,但不能在模拟器上复制。我不确定我们是否需要请求android中的一些新权限。

我终于用sqlite设置创建了一个新的xamarin表单项目。我使用了pcl库和ef核心。我仍然发现相同的错误。

这是复制问题的git枢纽https://github.com/neville-nazerane/xamarin-site

更新资料

只是我注意到的东西。早些时候,我的数据库文件名为“ main.db”。现在,无论我将该文件名更改为什么或更改任何变量。它在日志中始终将数据库名称显示为“ main”。不知道更改数据库名称是否可以解决该问题。但是,从未找到更改此数据库名称的方法。我尝试了不同的连接字符串,它只是说“数据库”和“ db”是未知键

更新资料

复制步骤:

using (var db = new AppDbContext())
{
    db.Add(new Person {
        Age = 55, 
        Name = "Neville"
    });
    db.SaveChanges();
    Person[] alldata = db.People.ToArray();
}
Run Code Online (Sandbox Code Playgroud)

的定义PersonAppDbContext是相当明显的。因此,本着不让问题太长的精神,我不在此发布。但是,如果需要,我也可以发布它们。

xamarin.android xamarin.forms entity-framework-core sqlite-net-pcl

5
推荐指数
1
解决办法
570
查看次数

'SQLite.SQLiteConnection'的类型初始值设定项引发了异常

我正在尝试实现SQLite的基本用法。我有一个Button和一个EditText。我要存储的内容EditText OnClick

我正在关注:https : //developer.xamarin.com/guides/android/application_fundamentals/data/part_3_using_sqlite_orm/

https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/databases/

我无法通过下面的启动代码,而没有得到随后的错误: var db = new SQLiteConnection (dbPath);

错误:

“ SQLite.SQLiteConnection”的类型初始值设定项引发了异常。

内部异常:

System.Exception:这是“诱饵”。您可能需要将SQLitePCLRaw.bundle_ * nuget包之一添加到平台项目中。
在SQLitePCL.Batteries_V2.Init()[0x00000]在<9baed10c674b49e0b16322f238b8ecc1>:0在/Users/vagrant/git/src/SQLite.cs:169的SQLite.SQLiteConnection..cctor()[0x00000]处

我已经在PCL和Android项目上都安装了NuGet软件包。我看到安装了以下软件包:

SQLitePCLRaw.provider.e_sqlite3.android
SQLitePCLRaw.lib.e_sqlite3.android
Run Code Online (Sandbox Code Playgroud)

我试过安装:

SQLitePCLRaw.bundle_e_sqlite3
Run Code Online (Sandbox Code Playgroud)

如前所述,代码是可能的最基本实现:

try
{
    string dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "TestDB-DEV.db3");

    var db = new SQLiteConnection(dbPath);
    db.CreateTable<PersonName>();
}
Run Code Online (Sandbox Code Playgroud)

我花了几天时间,尝试了许多资源,例如:https : //forums.xamarin.com/discussion/87289/sqlite-net-pcl-bait-issue,但最终没有成功。

不幸的是,我所见过的唯一答案就是胡说八道,例如“它能正常工作”,“不确定我做了什么”,“清理/重建”,例如以前的链接,其他诸如Xamarin SQLite之类的SO帖子“这是'诱饵'”。

这是我package.config的Android项目:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="sqlite-net-pcl" version="1.4.118" targetFramework="monoandroid60" />
  <package id="SQLitePCLRaw.bundle_green" version="1.1.5" targetFramework="monoandroid60" />
  <package id="SQLitePCLRaw.core" version="1.1.5" targetFramework="monoandroid60" …
Run Code Online (Sandbox Code Playgroud)

c# xamarin.android xamarin sqlite-net-pcl

4
推荐指数
4
解决办法
4415
查看次数

SQLiteAsyncConnection -&gt; CreateTablesAsync&lt;T&gt;() 需要两个类型参数

OS/X Mac Xamarin Forms Visual Studio Pro 2017

我正在尝试学习 Mosh Hamedani 关于 Xamarin 表单的精彩课程。我尝试编写第 89 讲中的相同代码:

var connection = DependencyService.Get<ISQLiteDb>().GetConnection();
connection.CreateTablesAsync<Recipe>();
Run Code Online (Sandbox Code Playgroud)

但是...我收到错误:

使用通用方法... CreateTablesAsync < t1 , t2 > () 需要 2 个类型参数

但即使是Xamarin 文档也没有这么说!它仅显示您希望将表创建为的表类类型的一种类型参数。

我该如何解决这个问题?

xamarin.forms sqlite-net-pcl

1
推荐指数
1
解决办法
371
查看次数

如何在 Xamarin.Forms 中使用 SQLite-net-plc 中的“.OrderBy”?

我想对保存在 SQLite 数据库中的日历条目进行排序,以便在列表视图中显示它们。如何使用 SQLite-net-plc 订购它们?

我以为我可以写:.OrderBy<CalendarEntryStartDate>但它不起作用,我尝试使用 SQLite 命令,但在使用它们时遇到了一些麻烦,因为我对 m.db 感到困惑。

using System;
using SQLite;

namespace Stundenplan.Models
{
    public class CalendarEntry
    {
        [PrimaryKey, AutoIncrement]
        public int CalendarEntryId { get; set; }
        public string CalendarEntryTitle { get; set; }
        public string CalendarEntryDescription { get; set; }
        [Column("StatDate")]
        public DateTime CalendarEntryStartDate { get; set; }
        public DateTime CalendarEntryEndDate { get; set; }
        public TimeSpan CalendarEntrySpan { get; set; }
        public string CalendarEntryParticipants { get; set; }
        public string CalendarEntrytLocation { get; …
Run Code Online (Sandbox Code Playgroud)

c# sqlite xamarin.forms sqlite-net-pcl

1
推荐指数
1
解决办法
2517
查看次数

.Result()使方法挂起时,如何在构造函数中使用异步方法?

当Xamarin.Forms项目中出现页面时,我有一个AppearingCommand调用,该页面最终执行以下sqlite-net-pcl行:(我已经有一种应对加载时间的机制)

AppearingCommand = new Command( async() => {
    //...
    var data = await db.Table<PlantCategory>().ToListAsync();
    //...
}
Run Code Online (Sandbox Code Playgroud)

我想将此方法移到构造函数中,但我不能这样做,因为如果同步执行它会挂起:

ctor() {
    //...
    var data = db.Table<PlantCategory>().ToListAsync().Result;
    //...
}
Run Code Online (Sandbox Code Playgroud)

该行永远不会返回(我猜是由于死锁或其他原因)。如果要在构造函数中执行此行,我还有什么其他选择?

c# sqlite mvvm xamarin.forms sqlite-net-pcl

0
推荐指数
1
解决办法
54
查看次数