sqlite 无法解析与数据库的连接

bksxznpy  于 2022-11-24  发布在  SQLite
关注(0)|答案(4)|浏览(179)

我添加了sqlite-net-plc并创建了Database类:

public class Database
{
    public Database()
    {
        var dbPath = Path.Combine(FileSystem.AppDataDirectory, "databaseTest.db3");

        Connection = new SQLiteAsyncConnection(dbPath);
        Connection.CreateTableAsync<User>().Wait();
    }

    public SQLiteAsyncConnection Connection { get; set; }
}

这适用于Android应用程序。但是,当我通过IOS模拟器与活跃的Mac连接运行时,我得到以下错误:
“SQLite.SQLiteConnection”得类型初始值设定项引发了异常.
我认为无法解决与SQLite数据库的连接,但为什么?

hgb9j2n6

hgb9j2n61#

在将sqlite-net-pcl添加到常用MAUI测试应用程序后,我在iOS和Android上都看到了相同的异常,直到我显式地将https://www.nuget.org/packages/SQLitePCLRaw.bundle_green/2.0.7包添加到项目中。
我看到,9月7日《生》包作者指出,他还有工作要做:https://github.com/ericsink/SQLitePCL.raw/discussions/449#discussioncomment-1282643
sqlite-net-pcl依赖于2.0.4版本的“原始”nuget,这是一年多的历史。也许2.0.7修复了一些与iOS相关的东西?我看到一些苹果特定的提交在https://github.com/ericsink/SQLitePCL.raw/commits/master在那个时间段。
也许你已经安装了一个更新的版本,修复了Android,但没有iOS?

eblbsuwk

eblbsuwk2#

要让iOS正常工作,我需要:
安装这些软件包

<PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
<PackageReference Include="SQLitePCLRaw.provider.sqlite3" Version="2.1.0" />
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.0" />

然后将Platforms.iOS.AppDelegate.cs更改为

[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
    protected override MauiApp CreateMauiApp()
    {
        raw.SetProvider(new SQLite3Provider_sqlite3());
        return MauiProgram.CreateMauiApp();
    }
}
omtl5h9j

omtl5h9j4#

我正在identnet7上开发.NET Maui应用程序,遇到了这个问题。将包SQLitePCLRaw.bundle_green更新到最新的2. 1. 2修复了这个问题。

相关问题