【发布时间】: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