I was struggling to find the solution to the following error while trying to update the database using code first migration.
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: 50 – Local Database Runtime error occurred. The specified LocalDB instance does not exist.
I managed to find the following, and I wish to know if there is any other way to solve the error.
My answer:
Make sure your SQL Server Management Studio is installed on your PC, an instance of your SQL Server should be SQLEXPRESS v11.0. Why V11.0? because Visual Studio Local DB for code first works well with version 11.0.
Go to SQL Server Configuration Manager, expand SQL Server Network Configuration and double click on Protocols for SQLEXPRESS.
Make sure Name pipes and TCP/IP are enabled.
Go back to your web application, click on your web.config. Your connection string should be
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-EMS_Events-20151217024735.mdf;Initial Catalog=aspnet-EMS_Events-20151217024735;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
make sure that it goes to (LocalDb)\v11.0.
Go to package manager console and run update-database.