简体   繁体   中英

Sqlite error WP8.1

I'm developing Windows phone 8.1 app. I have problem with Sqlite database. I created one, and made file. Now i want to use that file in my app, and get data from it.

I did create like this:

 SQLiteConnection.CreateFile(@"C:\ProbaProbe\MySql.sqlite");

 SQLiteConnection m_dbConnection;
        m_dbConnection = new SQLiteConnection("Data Source=C:\ProbaProbe\MySql.sqlite;Version=3;");
        m_dbConnection.Open();
        string sql = "create table highscores (name varchar(20), score int)";
        SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
        command.ExecuteNonQuery();

And i inserted some data with INSERT statment. That works nice. Now, when i want to use that MySql.sqlite in Windows Phone 8.1 app, i have problems. I did this way:

 private async Task CopyDatabase()
    {
        string DB_PATH = Path.Combine(@"C:\ProbaProbe\MySql.sqlite");
        bool isDatabaseExisting = false;

        using (var db = new SQLite.SQLiteConnection(DB_PATH))
        {
            isDatabaseExisting = true;
            grad q = new grad();
            SQLiteCommand sqlComm = new SQLiteCommand(db);   
            string a = (db.Query<grad>("select * from grad")[0]).Ime;
        catch
        {
            isDatabaseExisting = false;
        }


    }

Problem is: Could not open database file: C:\\ProbaProbe\\MySql.sqlite (CannotOpen)

I think i'm missing something... Anyone? Thx

You can't access system directories on Windows Phone. Applications on WP work in sandbox, so you can only access local storage available only for your application.

You could use connection string like this ( Local database for Windows Phone 8 ):

isostore:/MySql.sqlite

If you need to copy your database file into phone's or emulator's storage you could use Windows Power Tools .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM