加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-14 02:05:40 所属栏目:Windows 来源:网络整理
导读:我正在尝试在 Windows 8.1 Modern UI应用程序中实现数据库. 我成功地为Windows Phone 8.1应用程序做了这个,但它在新的Windows 8.1应用程序中不起作用. 当我实例化SQLiteConnection时,我收到了一条消息无法打开数据库文件的SQLiteException:MyAppBase.db(Can
我正在尝试在 Windows 8.1 Modern UI应用程序中实现数据库.
我成功地为Windows Phone 8.1应用程序做了这个,但它在新的Windows 8.1应用程序中不起作用.

当我实例化SQLiteConnection时,我收到了一条消息无法打开数据库文件的SQLiteException:MyAppBase.db(CannotOpen)

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

            return _instance;
        }
    }

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

        _connection.CreateTable<UserEntity>();
    }

我按照以下步骤操作:
在项目引用,Targetted build to x86上添加’sqlite-net’到Nuget引用,Checked’SQLite for Windows Runtime(Windows 8.1)’和’Microsoft Visual C 2013 Runtime Package for Windows’.

我怎样才能使这个工作?

解决方法

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

尝试这样的事情

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

_connection = new SQLite.SQLiteConnection(path)

希望这可以帮助

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读