0

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.

3
  • Please add a tag for database+version Commented Dec 4, 2016 at 9:35
  • Its v11.0 i can not find db version under tags Commented Dec 4, 2016 at 9:41
  • You should post your answer as an answer, not as part of the question. Commented Apr 4, 2017 at 7:40

1 Answer 1

3

I had a lot of problems trying to use default options. I prefer to specify the connection string when I'm using Add-Migration or Update-Database. I also can use development servers instead of SQL Express.

Add-Migration AddSomeThing -ConnectionString "Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-EMS_Events-20151217024735.mdf;Initial Catalog=aspnet-EMS_Events-20151217024735;Integrated Security=True" -ConnectionProviderName "System.Data.SqlClient" -Verbose

Update-Database -ConnectionString "Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-EMS_Events-20151217024735.mdf;Initial Catalog=aspnet-EMS_Events-20151217024735;Integrated Security=True" -ConnectionProviderName "System.Data.SqlClient" -Verbose
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.