Switching from automatic EF migration to code-first migration

I'm currently trying to switch from Entity Framework automatic migration to code-one transitions. For a little background, this solution is divided into four separate projects: data, models, services, and the web. The connection string information is in the web project, and the context is in the data project.

Now I have run "Enable-Migrations" and it seems to work correctly.

From there, I delete the existing migrationHistory table in the database.

Performance

Add-Migration -projectName Data" 

will create the appropriate migration.

The problem is that when I try to run Update-Database, this leads to a common error:

 > 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: SQL > Network Interfaces, error: 26 - Error Locating Server/Instance > Specified) 

I can connect to the database using the credentials provided in the web.config file, and the database connections have worked properly for the past few months, so I don’t think this is a connection problem, except when for transitions Code-First requires a different port than automatic migration.

I assumed that he just did not see the connection string contained in the web.config file, however it works

 Update-Database -projectName data -startupprojectname web 

leads to the same error

My question is:

How do I get around a common network error, given the above information? Is this a visiblity issue in which data code project code migration cannot see the connection string in a web project?

+6
source share
1 answer

The first code migrations - which connection string will be used?

Setting connectionStringName in Update-Database / Add-Migration worked correctly.

 Update-Database -projectName Data -connectionStringName MyConnectionString 
+1
source

Source: https://habr.com/ru/post/978639/


All Articles