How to merge two SQL databases into one with two EF contexts? RRS feed

  • Question

  • User-342859854 posted

    Hello, I have two SQL databases, each with code first EF 6.x context.

    I would like to merge these 2 databases into one database (containing data from both (tables have different names)), and preserve 2 separate independent existing 'code first' db contexts. Both contexts have some existing migrations and are in fact in different applications (one is mvc, one is web api).

    Has anyone done this before?

    Databases are on Azure as SQL Server databases.

    I used Visual Studio SQL object explorer to "extract data-tier application" to save schema and data from one db into local file and then with "publish data-tier application" I pushed that to the second database. Now I have database with tables and data from both databases, so far so good.

    Then I copied the missing migrations from first database to second co the migration table contains rows from both databases.

    Now when I run one application (web api) it is running just fine, but the other one (mvc) ends on exception seemingly the first time it is trying to access data. It ends on a rather unhelpful exception: "A task was canceled."

    What am I missing? Is there anything else I need to do? Has anyone done this before? How can I get some better exception with better description?

    Tuesday, June 26, 2018 10:14 AM

All replies

  • User753101303 posted


    You are showing ex.Message rarther than ex.ToSring() ? The later should give more détails including the inner exception and the call stack.

    Tuesday, June 26, 2018 10:46 AM
  • User-342859854 posted

    To answer my own question, it seems that the problem was just with insufficient database performance on Azure. When I increased the database performance from S0 tier to S2 tier, it time-outs no more. Probably as one app (web api) was querying the database, the other app (mvc) just timed out due to slow performance and low concurrency possibilities on S0 tier..

    Tuesday, June 26, 2018 11:40 AM