在Windows Store应用中的SQLite异常

4

在我的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 SDKs\Windows\v8.1\ExtensionSDKs\SQLite.WinRT81\3.8.5\”,并发现该DLL在所有配置(ARM、x64、x86)中都存在。
对于 Windows 运行时 SQLite(Windows 8.1)(版本 3.8.5.0)和 SQLitePCL(v4.0.30319)的引用已正确设置。
有什么想法吗?
1个回答

5

尽管我已经多次完成此操作,但我又一次删除了 Windows Runtime (Windows 8.1)的参考。但这一次,我还删除了 Microsoft Visual C++ 2013 运行时程序包的参考。在我重新添加这两个参考之后,问题消失了。


幸运的是,我在UWP应用程序中遇到了类似的问题,无法加载dll sqlite3.dll指定的模块无法在uwp中找到 - hal9k2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接