I am currently attempting to switch from Entity Framework Automatic Migrations to Code-First Migrations. For a little backstory, this solution is split into four seperate projects: Data, Models, Services, and Web. The connection string information is located in the Web project, and the context is located in the data project.
Now, I have ran "Enable-Migrations", and that appears to have worked correctly.
From there, I delete the existing migrationHistory table in the database.
Running
Add-Migration -projectName Data"
will generate an appropriate migration.
The Problem is when I attempt to run Update-Database, it results in a generic 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 supplied in the web.config, and the database connections have worked appropriately for the past several months, so I do not believe it is a connectivity problem unless Code-First migrations requires a different port than Automatic Migration.
I assumed that it was just not seeing the connection string supplied in the web.config, however running
Update-Database -projectName data -startupprojectname web
results in the same error
My question:
How do I get around the generic network-related error, given the above information? Is this problem a visiblity problem, in which the data project code-first migrations cannot see the connection string in the web project?
There are those of us that think that "code migration" means "convert code from one language/platform to another" and that "automatic migration" means "do code migration automatically".
To revert the last applied migration you should (package manager console commands): Revert migration from database: PM> Update-Database <prior-migration-name> Remove migration file from project (or it will be reapplied again on next step) Update model snapshot: PM> Remove-Migration.
Code first migrations - what connection string will it use?
Specifying the connectionStringName in the Update-Database / Add-Migration worked properly.
Update-Database -projectName Data -connectionStringName MyConnectionString
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With