0

I am trying to change the location of the database file in my Windows Phone 8 app.

The default constructor places it in the root isolated storage directory: /MyDbFile.sdf/

public MyDataContext() : base("Data Source=isostore:/MyDbFile.sdf") { }

My goal is to put it in /db/MyDbFile.sdf

What I have tried (yes, I know that some of them are silly):

public MyDataContext() : base("Data Source=isostore:/db/MyDbFile.sdf") { }
public MyDataContext() : base("Data Source=isostore:/db\\MyDbFile.sdf") { }
public MyDataContext() : base("Data Source=isostore:\\db/MyDbFile.sdf") { }
public MyDataContext() : base("Data Source=isostore:\\/db/MyDbFile.sdf") { }
public MyDataContext() : base("Data Source=isostore:/db//MyDbFile.sdf") { }
public MyDataContext() : base("Data Source=isostore:/db\\/MyDbFile.sdf") { }

What is the proper way to do this? Is it even possible?

1 Answer 1

2

Figured it right after writing this question. You have to create the target directory first.

using (var iso = IsolatedStorageFile.GetUserStoreForApplication())
{
    if (!iso.DirectoryExists("db"))
    {
        iso.CreateDirectory("db");
    }
}
_MyDataContext = new MyDataContext();

After that it works with:

public MyDataContext() : base("Data Source=isostore:/db/MyDbFile.sdf") { }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.