Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy SqlCe Database into isolatedStorage for windows phone

say, I want to use an existing SqlCe Database which HAS data in it. I am not sure which is the best way to do it.

1) here is the normal way to create a SqlCe Database for Windows phone

using (CountryDataContext context = new CountryDataContext(ConnectionString))    
    {         
        if (!context.DatabaseExists())        
        {            

        // create database if it does not exist            
            context.CreateDatabase();        
        }    
    }   

But this Database has data in it , so I dont want to create it. I want to deploy it or store in in isolatedStorage.

How should I do it ?? I want to use the data already in the database.

Thanks

like image 361
MilkBottle Avatar asked Jul 15 '11 13:07

MilkBottle


2 Answers

You can include the database file as Content in your application project and it will then be put in your XAP at build time and copied to your application install directory on the phone.

Will you modify this database at all?

  • If not: you can access the database directly from the install directory and future updates will get any new version of the database automatically (as long as you remember to add them to the XAP).

  • If you do modify it: then on first install you will need to copy the database to isolated storage before you use it. You will need to watch out if you update the database scheme with a future update.
  • like image 180
    Paul Annetts Avatar answered Oct 15 '22 19:10

    Paul Annetts


    Usually the pattern is to create the database and to configure seed data with it.

    Alternatively, if the database is read-only, you can deploy it with your application. See How to: Deploy a Reference Database with a Windows Phone Application on MSDN.

    If you want to deploy a database from your development machine for testing purposes, you can use the the ISETool that can take and restore snapshots of an application's isolated storage to/from a local directory:

    # Copy data from IS to directory
    ISETool.exe ts xd <PRODUCT-ID> "C:\TempDirectory\IsolatedStore"
    
    # Copy data to IS from directory
    ISETool.exe rs xd <PRODUCT-ID> "C:\TempDirectory\IsolatedStore"
    
    like image 29
    Richard Szalay Avatar answered Oct 15 '22 20:10

    Richard Szalay