MilkBottle
MilkBottle

Reputation: 4332

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

Upvotes: 5

Views: 1366

Answers (2)

Richard Szalay
Richard Szalay

Reputation: 84784

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"

Upvotes: 3

Paul Annetts
Paul Annetts

Reputation: 9604

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.

    Upvotes: 3

  • Related Questions