簡體   English   中英

.NET 毛伊島 SQLite 連接

[英].NET Maui SQLite Connection

我已將 sqlite-net-plc package 添加到我的項目中,並創建了一個數據庫 class,如下所示:

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 應用程序,允許我從任何地方操作數據庫。

但是,當我通過具有活動 Mac 連接的 IOS 模擬器運行此應用程序時,我收到以下錯誤:

'SQLite.SQLiteConnection' 的類型初始化程序引發了異常。

我相信無法解決與 SQLite 數據庫的活動連接,但我不知道為什么。 對此的任何見解都會很棒。

提前致謝。

在將 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 上看到了一些 Apple 特定的提交。

也許你已經安裝了一個更新的版本,它有針對 Android 的修復,但沒有針對 iOS?

問題在 github 上回答: https : //github.com/dotnet/maui/issues/3211

讓我讓 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();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM