5

我正在尝试在我的 Windows 8.1 Modern 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。

我怎样才能让这个工作?

4

2 回答 2

9

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

尝试这样的事情

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

_connection = new SQLite.SQLiteConnection(path)

希望这可以帮助

于 2014-10-03T21:00:07.600 回答
0

利用

string path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, databasePath);
于 2017-09-29T11:59:56.493 回答