【问题标题】:How to use SQLite in both Windows Phone 8.1 Silverlight Application and WinRT Runtime Component [duplicate]如何在 Windows Phone 8.1 Silverlight 应用程序和 WinRT 运行时组件中使用 SQLite [重复]
【发布时间】:2015-08-04 19:02:19
【问题描述】:

我有一个 Windows Phone Silverlight 8.1 应用程序,我想使用 Windows 运行时组件作为后台任务。在这两个项目中,我都想使用 SQLite 来访问应用程序数据库。

我在这里发现了一个类似的问题:

How to use SQLite in Windows (Phone) 8.1's BackgroundTask

这几乎涵盖了情况,但并不完全。关于如何实现我所要求的任何想法?

我可以非常“接近”,我在编译阶段得到的最新错误消息如下:

Payload contains two or more files with the same destination path 'sqlite3.pdb'. Source files: C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v8.0\ExtensionSDKs\SQLite.WP80\3.8.11.1\Redist\Debug\ARM\sqlite3.pdb C:\Program Files (x86)\Microsoft SDKs\WindowsPhoneApp\v8.1\ExtensionSDKs\SQLite.WP81\3.8.11.1\Redist\Debug\ARM\sqlite3.pdb

我看到这种类型的其他错误的解决方案是在其中一个引用上简单地将 Copy Local 设置为 false,但我不知道在这种情况下这如何可能,因为实际上两者都是必需的。

提前致谢!

更新 1: 使用下面 scottisafool​​ 的建议,我已经从 SQLite SDK 文件夹中删除了 pdb 文件,这让我更进一步,即它至少现在可以编译。但是,然后我遇到了另一个问题......

然后,我开始在后台任务中删除用于访问数据库的代码,并且在使用“不是有效的 WinRT 类型”跳过一些循环之后,我正处于编译的地步,看起来应该工作。但是,当我尝试运行应用程序并运行之前运行良好的代码时,即在应用程序首次加载时创建数据库时,我遇到了这个错误:

The specified module could not be found. (Exception from HRESULT: 0x8007007E)

使用以下堆栈跟踪:

at System.StubHelpers.StubHelpers.GetWinRTFactoryObject(IntPtr pCPCMD) at Sqlite.Sqlite3.sqlite3_open_v2(String filename, Database& db, Int32 flags, String zVfs) at SQLite.Net.Platform.WindowsPhone8.SQLiteApiWP8.Open(Byte[] filename, IDbHandle& db, Int32 flags, IntPtr zVfs) at SQLite.Net.SQLiteConnection..ctor(ISQLitePlatform sqlitePlatform, String databasePath, SQLiteOpenFlags openFlags, Boolean storeDateTimeAsTicks, IBlobSerializer serializer, IDictionary`2 tableMappings, IDictionary`2 extraTypeMappings, IContractResolver resolver) at SQLite.Net.SQLiteConnection..ctor(ISQLitePlatform sqlitePlatform, String databasePath, Boolean storeDateTimeAsTicks, IBlobSerializer serializer, IDictionary`2 tableMappings, IDictionary`2 extraTypeMappings, IContractResolver resolver) at DatabaseContext.OnCreate(String databaseFilePath)

更新 2: 上述错误消息在我将 Windows Phone 8.1 可移植类库(包含所有 SQLite 代码)的引用添加到 BackgroundTask Windows 运行时组件项目时发生。必须在这一点上:

  • 适用于 Windows Phone 8.1 的 SQLite
  • 适用于 Windows Phone 的 SQLite

SDK 都被拉入到完整的应用程序中。此时,我假设正在引入 Windows Phone 8.1 引用,但没有引入 Windows Phone 引用,因为它被视为已经存在。这是完全的猜想,但它似乎与我所看到的相符。关于如何进行的任何想法?谢谢!

【问题讨论】:

    标签: sqlite silverlight windows-runtime windows-phone-8.1 winrt-component


    【解决方案1】:

    我找到了解决办法:

    仅在 Silverlight 应用项目中添加对 SQLite dll 的引用,在后台任务项目(WinRT 运行时组件)中不添加任何内容。

    SQLite.net nuget 库将在运行时在应用项目和后台任务项目(WinRT 运行时组件)中找到 dll。

    【讨论】:

      【解决方案2】:

      从 nuget 包中删除 pdb 文件。

      【讨论】:

      猜你喜欢
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 2014-09-07
      • 2016-09-05
      • 2016-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多