0

I get the following error after running update-database command in Package Manager Console

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.

I was following Complete ASP.NET MVC 5 Course by Mosh-Hamedani and I was doing Code-First Migration.

How to debug this error? Is this the issue of using different versions of VS? What steps should I take in order to determine what is really going on here, in addition to the one mentioned in the error message?

Ilias
  • 71
  • 1
  • 6
  • 2
    What connection string are you using? Can you connect using SSMS? – gunr2171 Sep 28 '22 at 18:41
  • If publicly available, consider linking the course you're referencing. Or better yet, distill the steps to a minimal reproducible example. These errors aren't always easy to diagnose without a good context of what you're actually doing – acat Sep 28 '22 at 23:31

1 Answers1

0

Solution:

Connection strings using "127.0.0.1", "localhost" and "." will not work.

It may be that you have multiple versions of SqlServer installed on your computer.

You have to use the machine name + service name.

Data Source=DESKTOP-46PCO3Q\MSSQLSERVER2017.

Note: The reason why the SQL Server database link fails the most is that the ip is blocked and the port is blocked.

  1. Check whether the SqlServer port is open to the outside world.

  2. Use the telnet command to test whether the remote port is open.

    Reference: Use the Telnet command to test the port number under Windows.

  3. Another possibility is that there is a problem with the Tcp/IP protocol of the cloud server.

    For example, when there are multiple network connections in use, or there are multiple networks, the port will be blocked.

    The solution is to disable one of the networks.

Reference link: Enable remote connections for SQL Server Express 2012.

Hope it helps you.

Housheng-MSFT
  • 1
  • 1
  • 1
  • 9