[英]SQLite UWP Error with Mobile EMulator Windows 10
我在嘗試編譯和運行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()
我有以下參考:SQLite for Universal Windows 3.9.1 sqlite-net-pcl Microsoft Visual C ++ 2013 Runtime Package for Universal Windows
“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
以下是我如何使用SQLite:
從http://sqlite.org/download.html下載並安裝Sqlite visual studio擴展
創建一個新的空白c#通用Windows平台應用程序。
右鍵單擊項目的引用 - >添加引用 - >通用Windows - >擴展 - >為通用應用程序平台添加SQLite及其依賴項Visual C ++ 2015 Runtime for Universal Windows
將您的代碼更改為以下內容:
using (var db = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), dbPath)) { ... }
步驟1:使用Visual Studio 2015安裝SQLite VSIX pacakge以進行通用Windows平台開發
https://www.sqlite.org/2016/sqlite-uwp-3130000.vsix
第2步:安裝NuGet包SQLite.NET-PCL
PM>安裝包SQLite.NET-PCL
第3步:添加引用
添加引用 - >通用Windows - >擴展 - >確保已檢查以下包:“SQLite for Universal Windows Platform”“Visual C ++ 2015 Runtime for Universal Windows Platform Apps”
如果您沒有為VC ++ 2015 Runtime添加引用,那么在創建數據庫連接時,您將收到一條錯誤,提到“無法在SQLite Net Platform WinRT中加載DLL'sqlite3”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.