1
votes

In trying to follow this example.

After scaffolding, when I'm trying to execute the commands:

Add-Migration InitialCreate

Update-Database

I receive this 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 have already configured tcp protocols, allowed the tcp ports through firewall, but with no success.

2

2 Answers

1
votes

The problem might be in your connection string.

 "Server=localhost;Database=DatabaseNameHere;Trusted_Connection=True;MultipleActiveResultSets=true"

Ensure it uses either localhost or localhost\SQLEXPRESS, depending on your SQL Server installation.

The microsoft docs describe the exact steps to resolve this issue, it almost always has something to do with a typo in de name of the server instance.

https://blogs.msdn.microsoft.com/sql_protocols/2007/05/13/sql-network-interfaces-error-26-error-locating-serverinstance-specified/

To quote:

In a word, the reason that we get this error message is the client stack could not receive SSRP response UDP packet from SQL Browser. It's easy to isolate the issue. Here are the steps:

1) Make sure your server name is correct, e.g., no typo on the name.

2) Make sure your instance name is correct and there is actually such an instance on your target machine. [Update: Some application converts \ to . If you are not sure about your application, please try both ServerInstance and Server\Instance in your connection string]

3) Make sure the server machine is reachable, e.g, DNS can be resolve correctly, you are able to ping the server (not always true).

4) Make sure SQL Browser service is running on the server.

5) If firewall is enabled on the server, you need to put sqlbrowser.exe and/or UDP port 1434 into exception.

0
votes

The (provider: Named Pipes Provider, error: 40) after (provider: SQL Network Interfaces, error: 26) appears mostly when SQL Server does not allow remote connections, Firewall Settings or TCP/IP is not enabled.

Some fast trobleshoot steps are:

  1. Check SQL Server is running
  2. Make sure that Allow Remote Connections is enabled on sql server properties
  3. Check if TCP/IP is enabled
  4. Configure to allow SQL Server in Firewall Settings
  5. Check for working fine SQL Server Browser
  6. Make sure that you can ping the SQL Server

The following source explain the above steps in long way for better understanding: https://www.get-itsolutions.com/sql-server-error-26-sql-error-40-fix/