Last post Jul 20, 2020 01:19 AM by yinqiu
Jul 18, 2020 10:03 AM|Rob warning|LINK
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?
Jul 18, 2020 11:02 PM|PaulTheSmith|LINK
The docs you link to say
but you are passing a filename. You need to give the name of the class.
Jul 20, 2020 01:19 AM|yinqiu|LINK
Hi Rob warning,
You can do this for multiple dbcontext migrations:
add-migration inicial -context ApplicationDbContextupdate-database -context ApplicationDbContext
Hope this can help you.