Migration with dual Database context RRS feed

  • Question

  • User-959394753 posted


    For a long time I have been struggling with the problem that with EF migrations my Update-database command fails with the message : A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

    reading https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell I see that if there are multiple DBContext classes in your project the  -Context<string> syntax should be used.

    since I have two database context classes in my Data folder ie. ApplicationDbContect.cs and RoosterContectFactory.cs I havebeen trying :

    PM> update-database -Context ApplicationDbContext.cs ,

    PM> update-database -Context Data/ApplicationDbContext.cs and

    PM> update-database -Context data/ApplicationDbContext

    but every time with a failing message No DbContext named 'data/ApplicationDbContext' was found.

    what is the right syntax for this command?



    Saturday, July 18, 2020 10:03 AM

All replies

  • User303363814 posted

    The docs you link to say

    -Context <String> The DbContext class to use. Class name only or fully qualified with namespaces. 

    but you are passing a filename.  You need to give the name of the class.

    Saturday, July 18, 2020 11:02 PM
  • User-217098811 posted

    Hi Rob warning,

    You can do this for multiple dbcontext migrations:

    add-migration inicial -context ApplicationDbContext

    update-database -context ApplicationDbContext

    Hope this can help you.

    Best Regards


    Monday, July 20, 2020 1:19 AM