Could not open database file Windows Store App 8.1
Asked Answered
I

2

5

I'm trying to implement a database in my Windows 8.1 Modern UI application. I made this for a Windows Phone 8.1 app successfully, but it doesn't work in a new Windows 8.1 app.

I got a SQLiteException with message Could not open database file: MyAppBase.db (CannotOpen) when i instanciate SQLiteConnection

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

            return _instance;
        }
    }

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

        _connection.CreateTable<UserEntity>();
    }

I follow this steps : Added 'sqlite-net' to Nuget reference, Checked 'SQLite for Windows Runtime (Windows 8.1)' and 'Microsoft Visual C++ 2013 Runtime Package for Windows' on project references, Targetted build to x86.

How can i get this working ?

Instrumentalism answered 3/10, 2014 at 15:9 Comment(0)
A
9

SQLite needs a path to create a DB not just a db name

try something like this

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

_connection = new SQLite.SQLiteConnection(path)

Hope this helps

Auckland answered 3/10, 2014 at 21:0 Comment(1)
Ah. Of course, it has to go with the app. Thanks! For some dumb reason I thought I could use "C:\temp\" or another folder.Unity
O
0

Use

string path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, databasePath);
Outbuilding answered 29/9, 2017 at 11:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.