Windows 10移动版上的SQLite无法正常工作

时间:2016-06-12 21:17:34

标签: c# sqlite windows-runtime uwp

我想为我的应用创建这个SQLite数据库,每次尝试都会收到此错误。

类型' System.DllNotFoundException'的例外情况发生在SQLite.Net.Platform.WinRT.dll但未在用户代码中处理

我已经安装了SQLite for uwp,我添加了SQLite,用于添加到引用的通用应用程序(windows)平台。

它不会发生在Windows桌面上,只是移动设备的一个问题。

private string _dbPath = string.Empty;
    public string DbPath
    {
        get
        {
            if (string.IsNullOrEmpty(_dbPath))
            {
                _dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "Storage.sqlite");
            }

            return _dbPath;
        }
    }

    public SQLiteConnection DbConnection => new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), DbPath);

1 个答案:

答案 0 :(得分:2)

  

我安装了SQLite for uwp,我添加了SQLite,用于添加到引用的通用应用程序(windows)平台。   它不会发生在Windows桌面上,只是移动设备的一个问题。

根据您上面提供的代码,您正在使用SQLite的SQLite.Net-PCL NuGet包。

当我使用SQLite的SQLite.Net-PCL NuGet Package和仅添加“SQLite for Universal Windows Platform”时,我已经重现了这个问题。代码在本地计算机上运行正常但在Mobile Emulator和Windows Phone上失败。

根据我的研究,SDK“ SQLite for Universal Windows Platform ”依赖于SDK“ Visual C ++ 2015 Runtime for Universal Windows Platform Apps ”。

因此,在使用SQLite的SQLite.Net-PCL NuGet Package时,我们可能需要为通用Windows平台和“Visual C ++ 2015 Runtime for Universal Windows Platform Apps”添加两者“SQLite”。

如果只添加“ SQLite for Universal Windows Platform ”,我们会收到以下警告:

  

SDK“SQLite.UWP.2015,Version = 3.13.0”取决于以下SDK“Microsoft.VCLibs,version = 14.0”,这些SDK尚未添加到项目中或未找到。请确保将这些依赖项添加到项目中,否则可能会遇到运行时问题。您可以通过Reference Manager将依赖项添加到项目中。

添加两个引用后,警告消失,问题得到解决。

相关问题