locked
How to load database from a specified path?

    Question

  • I'm using Lex.db as my questions database.

    I've a "Questions" folder in the solution explorer..which has *.index & *.data files.

    Now I want the path of that Questions folder 

    here is what I'm trying

    string path = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path,@"Questions");
    
    db = new DbInstance(path);

    But I'm getting an exception of type "System.IO.IOException".

    What I'm exactly doing is loading the "Lex.Db" files for entering new questions. Is there anyone to help me?


    Clipr : Best ever clipping tool in Windows Phone!
    Download here

    Saturday, April 26, 2014 7:31 PM

Answers

  • While I agree with Rob, it seems this is an issue where you do not have "copy always" action selected for your database files in solution. Two more things you need to take care of once it starts to read them A) From your solution stuff will be copied to install folder of app, there you can only read stuff but not write/update. For this generally you need to copy that file to Local Folder ( isolated storage for app) and then use it. B) These database files are generally binary files and hence platform dependent, i.e. ARM vs x86 vs x64. If yours is that case then make sure you either have a app startup function that actually creates database from scratch for the first time on user machine (not part of solution) or you have one for all of the platforms and you choose appropriate file during package creation. For further help talk to Lex.

    -- Vishal Kaushik --

    Please 'Mark as Answer' if my post answers your question and 'Vote as Helpful' if it helps you. Happy Coding!!!

    • Marked as answer by venu238 Sunday, April 27, 2014 12:14 PM
    Sunday, April 27, 2014 7:50 AM
  • You'll have to talk to the authors of lex for help specific to that database.

    that said, you won't have write access to the installed directory. You'll have only read access there. If you need write access you'll need to put it in the app data directory.

    • Marked as answer by venu238 Sunday, April 27, 2014 12:14 PM
    Saturday, April 26, 2014 11:46 PM
    Owner

All replies

  • You'll have to talk to the authors of lex for help specific to that database.

    that said, you won't have write access to the installed directory. You'll have only read access there. If you need write access you'll need to put it in the app data directory.

    • Marked as answer by venu238 Sunday, April 27, 2014 12:14 PM
    Saturday, April 26, 2014 11:46 PM
    Owner
  • While I agree with Rob, it seems this is an issue where you do not have "copy always" action selected for your database files in solution. Two more things you need to take care of once it starts to read them A) From your solution stuff will be copied to install folder of app, there you can only read stuff but not write/update. For this generally you need to copy that file to Local Folder ( isolated storage for app) and then use it. B) These database files are generally binary files and hence platform dependent, i.e. ARM vs x86 vs x64. If yours is that case then make sure you either have a app startup function that actually creates database from scratch for the first time on user machine (not part of solution) or you have one for all of the platforms and you choose appropriate file during package creation. For further help talk to Lex.

    -- Vishal Kaushik --

    Please 'Mark as Answer' if my post answers your question and 'Vote as Helpful' if it helps you. Happy Coding!!!

    • Marked as answer by venu238 Sunday, April 27, 2014 12:14 PM
    Sunday, April 27, 2014 7:50 AM
  • Thanks i'm working on it, will post soon when it works

    Clipr : Best ever clipping tool in Windows Phone!
    Download here

    Sunday, April 27, 2014 12:10 PM
  • Actually I've filled half database in the windows phone, now I wanna continue filling the rest of  database using windows(as it eases out my work).

    Now it's working I've copied database in the app data and then accessed it from there.

    Here is how I did :)

                var lex = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Lex.Db",
                                        CreationCollisionOption.OpenIfExists);
                var auto = await lex.CreateFolderAsync("Questions",
                                CreationCollisionOption.OpenIfExists);
                StorageFile seedFile1 = await StorageFile.GetFileFromPathAsync(
                            Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path,
                                         @"Question.index"));
                StorageFile seedFile2 = await StorageFile.GetFileFromPathAsync(
                            Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path,
                                         @"Question.data"));
                await seedFile1.CopyAsync(auto, @"Question.index",
                            NameCollisionOption.ReplaceExisting);
                await seedFile2.CopyAsync(auto, @"Question.data",
                            NameCollisionOption.ReplaceExisting);

    Thank you both of you for helping me :)


    Clipr : Best ever clipping tool in Windows Phone!
    Download here

    Sunday, April 27, 2014 12:14 PM