c# - UWP - SQLite - 尝试加载格式不正确的程序

标签 c# sql-server sqlite asp.net-web-api uwp

我已经接管了一个使用 SQLite 数据库的 UWP 应用程序,并且与 WebService 在同一台 PC 上本地完美运行。我通过使用商店在 Microsoft Surface (x64 Windows 10 Professional) 上运行来创建包。

应用程序通过 PC 的 IP 调用 PC - x64 Windows 10 Professional 上的 ASP.Net 中的 SOAP WebService(它处于开发阶段,因此不在服务器上)。该 API 从 SQL Server 数据库创建 SQLite 数据库,并在另一个方法中返回它。

这是我的问题:

创建与 SQLite 数据库的连接时(我从与 WebService 位于同一台 PC 上的 .db 文件中使用 SqliteConnectionStringBuilder 获取连接字符串),出现错误:

An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

因此,我在不同的论坛上搜索并测试了不同的解决方案(在 x86/x64/ARM/任何 CPU 中生成 UWP 应用程序,在 x86/x64/任何 CPU 中生成 API),但没有任何效果。所以我真的不知道该怎么办。你有什么想法吗?

代码:

     /// <summary>
        /// Creates the SQLite database from the schema read from the SQL Server.
        /// </summary>
        /// <param name="sqlitePath">The path to the generated DB file.</param>
        /// <param name="schema">The schema of the SQL server database.</param>
        /// <param name="password">The password to use for encrypting the DB or null if non is needed.</param>
        private static void CreateSQLiteDatabase(string sqlitePath, DatabaseSchema schema, string password,bool createViews)
                {

                    // Create the SQLite database file
                    SQLiteConnection.CreateFile(sqlitePath);


                    // Connect to the newly created database
                    string sqliteConnString = CreateSQLiteConnectionString(sqlitePath, password);

                    //Here the exception
                    using (SQLiteConnection conn = new SQLiteConnection(sqliteConnString))
                    {
                        conn.Open();

                        ...

CreateSQLiteConnectionString方法:

/// <summary>
/// Creates SQLite connection string from the specified DB file path.
/// </summary>
/// <param name="sqlitePath">The path to the SQLite database file.</param>
/// <returns>SQLite connection string</returns>
private static string CreateSQLiteConnectionString(string sqlitePath, string password)
{
    SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder();
    builder.DataSource = sqlitePath;
    if (password != null)
        builder.Password = password;
    builder.PageSize = 4096;
    builder.UseUTF16Encoding = false;
    string connstring = builder.ConnectionString;

    return connstring;
}

不知道是不是缺少dll,这是我第一次使用UWP和SQLite。

预先感谢您的回答。

最佳答案

根据 StackOverflow 的问题建议,我找到了答案:

我必须在 IIS 中的应用程序池中允许 32 位应用程序。 (I get a "An attempt was made to load a program with an incorrect format" error on a SQL Server replication project)

关于c# - UWP - SQLite - 尝试加载格式不正确的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51732589/

相关文章:

c# - 是否可以使用 C# 检测 DTMF 音调

c# - 将 XML 文件读入 DataTable 的代码

c# - 在继承类中使用锁的最佳实践是什么

sql - 更改sql server脚本中的数据库名称

c# - 如何将任意 DataTable 保存到新的 SQL 表

android - 从 Recycler 列表中删除但不从 Sqlite 数据库中删除的数据

c# - .net core - 数据库 url 解析器

c# - 通过 SqlDataSourceEnumerator.Instance.GetDataSources() 完成枚举时,.NET 不显示实例或版本

sqlite - 无限保存 CoreData Context

sqlite - 32 位系统上 SQLite 的文件大小限制