【问题标题】:UWP - SQLite - An attempt was made to load a program with an incorrect formatUWP - SQLite - 试图加载格式不正确的程序
【发布时间】:2019-01-14 21:16:52
【问题描述】:

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

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

这是我的问题:

在创建与 SQLite 数据库的连接时(我从与 WebService 位于同一台 PC 的 .db 文件中获取带有 SqliteConnectionStringBuilder 的 connectionString),出现错误:

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

所以我在不同的论坛上搜索并测试了不同的解决方案(在 x86 / x64 / ARM / Any CPU 中生成 UWP 应用程序,在 x86 / x64 / Any 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。

提前感谢您的回答。

【问题讨论】:

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


【解决方案1】:

通过 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)

【讨论】:

    猜你喜欢
    • 2014-01-11
    • 1970-01-01
    • 2016-05-17
    • 2012-05-01
    • 2014-02-10
    • 2015-10-13
    • 1970-01-01
    • 2012-11-02
    • 1970-01-01
    相关资源
    最近更新 更多