UWP-SQLite-试图加载格式错误的程序

时间:2018-08-07 17:44:27

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

我已经接管了使用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。

预先感谢您的回答。

1 个答案:

答案 0 :(得分: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