1

My application creates tables like this:

    public DataAccess()
    {
        dbcon = DependencyService.Get<ISQLite>().GetConnection();
        // create the tables
        dbcon.CreateTable<Category>();
        dbcon.CreateTable<Settings>();

What I would like to do is to have two databases. One that holds all the user data and one that is refreshed when the application is updated.

As part of the update process I would like to add data from the new database to the existing user database.

Is it possible to open two connections to different databases and also how can I get data from one database and add it to the other? Could I for example do a SQL Select that sp[ans two databases?

1 Answer 1

2

The DependencyService is a simple IOC Container. It only supports getting either a new or a global instance for one interface.

One options here are to have different interfaces for your UpdateDatabase and your UserDatabase, so you could retrieve them (it could be an inherited inferface, or your db-class just implements them both):

var db1 = DependencyService.Get<ISQLite>().GetConnection();
var db2 = DependencyService.Get<ISQLiteUpdateDb>().GetConnection();

To copy over, you still have retrieve all data an then just insert into the second one:

var data = db1.Table<YourModel>().ToList();
db2.InsertAll(data);

(Assuming, you are using sqlite-net-pcl.)

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.