【问题标题】:SQLite UWP Error with Mobile EMulator Windows 10移动模拟器 Windows 10 的 SQLite UWP 错误
【发布时间】:2016-01-24 01:03:02
【问题描述】:

当我在尝试编译和运行 VS 2015 UWP 应用程序时运行 Mobile Emulator 时出现以下错误。该应用程序在使用本地机器或模拟器时运行良好。

   System.TypeInitializationException was unhandled by user code
  HResult=-2146233036
  Message=The type initializer for 'SQLitePCL.raw' threw an exception.
  Source=SQLitePCL.raw
  TypeName=SQLitePCL.raw
  StackTrace:
       at SQLitePCL.raw.sqlite3_open_v2(String filename, sqlite3& db, Int32 flags, String vfs)
       at SQLite.SQLiteConnection..ctor(String databasePath, SQLiteOpenFlags openFlags, Boolean storeDateTimeAsTicks)
       at SQLite.SQLiteConnection..ctor(String databasePath, Boolean storeDateTimeAsTicks)
       at App3.MainPage.LoadSQLData()
       at App3.MainPage..ctor()
       at App3.App3_XamlTypeInfo.XamlTypeInfoProvider.Activate_0_MainPage()
       at App3.App3_XamlTypeInfo.XamlUserType.ActivateInstance()
  InnerException: 
       HResult=-2146233052
       Message=Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
       Source=SQLitePCL.raw
       TypeName=""
       StackTrace:
            at SQLitePCL.SQLite3Provider.NativeMethods.sqlite3_win32_set_directory(UInt32 directoryType, String directoryPath)
            at SQLitePCL.SQLite3Provider..ctor()
            at SQLitePCL.raw..cctor()

我有以下参考资料: 通用 Windows 3.9.1 的 SQLite sqlite-net-pcl 适用于通用 Windows 的 Microsoft Visual C++ 2013 运行时包

在"using(var db......:

 int recCtr = 0;
        var root = Windows.Storage.ApplicationData.Current.LocalFolder.Path;
        var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "BaseBallOU.db");
        List<string> NHLCollection = new List<string>();
        using (var db = new SQLite.SQLiteConnection(dbPath))
        {
            var NHLlist = db.Table<Teams>().ToList();
            foreach (var item in NHLlist)
            {
                recCtr++;
                NHLCollection.Add(item.TeamName.ToString());
            }
        }

我看到许多类似的帖子,但有些过时了,并且没有使用最新的 SQLite 库和 pcls。

我正在寻找正确的 SQLite dll、sqlite pcls、运行时(例如 VC++ 2013?以及可用于在本地计算机和手机模拟器上编译和运行 UWP 应用程序的版本号。

TIA

【问题讨论】:

标签: c# sqlite uwp


【解决方案1】:

以下是我使用 SQLite 的方式:

  1. http://sqlite.org/download.html 下载并安装 Sqlite Visual Studio 扩展

  2. 创建一个新的空白 c# 通用 Windows 平台应用程序。

  3. 右键单击项目的引用 -> 添加引用 -> Universal Windows -> Extension -> 添加 SQLite for Universal App Platform 及其依赖 Visual C++ 2015 Runtime for Universal Windows

  4. 项目节点右键->管理NuGet包->搜索SQLite.Net-PCL->安装默认版本3.0.5

  5. 将您的代码更改为以下内容:

    using (var db = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), dbPath))
    {
        ...
    }
    

【讨论】:

  • 艾伦,我一步一步地按照你的例子,在本地机器和模拟器 X86/调试试验中都得到了以下错误消息。 System.DllNotFoundException 未被用户代码处理 HResult=-2146233052 消息=无法加载 DLL 'sqlite3':找不到指定的模块。 (来自 HRESULT 的异常:0x8007007E)Source=SQLite.Net.Platform.WinRT TypeName="" EmulatorTest1.EmulatorTest1_XamlTypeInfo.XamlUserType.ActivateInstance() InnerException:
  • 按照相同的步骤,我遇到了完全相同的问题,知道吗?
  • 这个问题是否出现在一个干净的空白项目中?如果是这样,请检查您的 VS 更新以确保您没有遇到任何已知的工具问题。
【解决方案2】:

第 1 步:安装 SQLite VSIX 包以使用 Visual Studio 2015 进行通用 Windows 平台开发

https://www.sqlite.org/2016/sqlite-uwp-3130000.vsix

第 2 步:安装 NuGet 包 SQLite.NET-PCL

PM> 安装包 SQLite.NET-PCL

第 3 步:添加参考文献

添加参考 -> 通用 Windows -> 扩展 -> 确保已检查以下包: “通用 Windows 平台的 SQLite” “通用 Windows 平台应用程序的 Visual C++ 2015 运行时”

如果您没有添加对 VC++ 2015 Runtime 的引用,您将在创建数据库连接时收到错误提示“无法在 SQLite Net Platform WinRT 中加载 DLL 'sqlite3'”。

【讨论】:

  • 我也试过另一个NuGet包“sqlite-net-pcl”,好像不需要其他包。
猜你喜欢
  • 2016-03-30
  • 2016-02-10
  • 2017-07-30
  • 1970-01-01
  • 2016-04-03
  • 1970-01-01
  • 2023-04-08
  • 2016-02-24
  • 2016-06-09
相关资源
最近更新 更多