gpt4 book ai didi

windows-store-apps - 无法打开数据库文件 Windows Store App 8.1

转载 作者:行者123 更新时间:2023-12-04 07:57:55 24 4
gpt4 key购买 nike

我正在尝试在我的 Windows 8.1 现代 UI 应用程序中实现一个数据库。
我成功地为 Windows Phone 8.1 应用程序制作了这个,但它在新的 Windows 8.1 应用程序中不起作用。

我收到了 SQLiteException留言 Could not open database file: MyAppBase.db (CannotOpen)当我实例化 SQLiteConnection

public static DatabaseHelper Instance
{
get
{
if (_instance == null)
{
_instance = new DatabaseHelper();
}

return _instance;
}
}

public DatabaseHelper()
{
_connection = new SQLiteConnection(DATABASE_NAME);

_connection.CreateTable<UserEntity>();
}

我按照以下步骤操作:
在 Nuget 引用中添加了“sqlite-net”,在项目引用中检查了“SQLite for Windows Runtime (Windows 8.1)”和“Microsoft Visual C++ 2013 Runtime Package for Windows”,目标构建到 x86。

我怎样才能让它工作?

最佳答案

SQLite 需要一个路径来创建一个数据库,而不仅仅是一个数据库名称

尝试这样的事情

string path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, DATABASE_NAME);

_connection = new SQLite.SQLiteConnection(path)

希望这可以帮助

关于windows-store-apps - 无法打开数据库文件 Windows Store App 8.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26181674/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com