C# Windows应用商店应用程序中的SQLite异常

C# Windows应用商店应用程序中的SQLite异常,c#,sqlite,windows-store-apps,windows-phone-8.1,C#,Sqlite,Windows Store Apps,Windows Phone 8.1,在我的Windows 8.1(商店)和Windows Phone 8.1通用应用程序中,我只有在商店应用程序中才能打开数据库,这是一个例外。这段代码对这两个应用程序都是共享的,对于Windows Phone,它正在工作 class MemoDB { public static SQLiteConnection conn; public MemoDB() { conn = LoadDatabase(); } static private SQL

在我的Windows 8.1(商店)和Windows Phone 8.1通用应用程序中,我只有在商店应用程序中才能打开数据库,这是一个例外。这段代码对这两个应用程序都是共享的,对于Windows Phone,它正在工作

class MemoDB
{
    public static SQLiteConnection conn;

    public MemoDB() { 
        conn = LoadDatabase();
    }

    static private SQLiteConnection LoadDatabase()
    {
       // Get a reference to the SQLite database
       conn = new SQLiteConnection("ct_history.sqlite");
    ...
    }
}
异常{“无法设置临时目录”。}发生在最后显示的代码行,详细信息如下:

SQLitePCL.SQLiteException was not handled by user code.
  HResult=-2146233088
  Message=Unable to set temporary directory.
  Source=SQLitePCL
  StackTrace:
       at SQLitePCL.SQLiteConnection.SetTemporaryDirectory()
       at SQLitePCL.SQLiteConnection..ctor(String fileName, Boolean setTemporaryDirectory)
       at SQLitePCL.SQLiteConnection..ctor(String fileName)
       at CTDICT.MemoDB.LoadDatabase()
       at CTDICT.MemoDB..ctor()
       at CTDICT.Dictionary..ctor()
       at CTDICT.CTDICT_Windows_XamlTypeInfo.XamlTypeInfoProvider.Activate_8_Dictionary()
       at CTDICT.CTDICT_Windows_XamlTypeInfo.XamlUserType.ActivateInstance()
  InnerException: SQLitePCL.SQLiteException
       HResult=-2146233088
       Message=Unable to open the database file: :memory:
       Source=SQLitePCL
       StackTrace:
            at SQLitePCL.SQLiteConnection..ctor(String fileName, Boolean setTemporaryDirectory)
            at SQLitePCL.SQLiteConnection.SetTemporaryDirectory()
       InnerException: System.DllNotFoundException
            HResult=-2146233052
            Message=DLL "sqlite3.dll": The specified module could not be found. (Exception from HRESULT: 0x8007007E) can not be loaded.
            Source=SQLitePCL.Ext
            TypeName=""
            StackTrace:
                 at SQLitePCL.SQLite3Provider.NativeMethods.sqlite3_open(IntPtr filename, IntPtr& db)
                 at SQLitePCL.SQLite3Provider.Sqlite3Open(IntPtr filename, IntPtr& db)
                 at SQLitePCL.SQLiteConnection..ctor(String fileName, Boolean setTemporaryDirectory)
            InnerException: 
在我看来,“DLL sqlite3.DLL:找不到指定的模块”指向了问题所在。我检查了路径“C:\Program Files(x86)\Microsoft SDK\Windows\v8.1\ExtensionSDKs\SQLite.WinRT81\3.8.5\”,并在所有配置(ARM、x64、x86)中找到了该DLL

正确设置了对SQLite for Windows Runtime(Windows 8.1)(版本3.8.5.0)和SQLite PCL(v4.0.30319)的引用


知道该怎么做吗?

即使我已经做了好几次,我还是再次删除了Windows运行时(Windows 8.1)的参考。但这次我删除了微软Visual C++ 2013运行时包的引用。在我再次添加这两个之后,问题就解决了。

你真幸运。我在UWP应用程序中遇到了类似的问题,