1

Problem is

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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server

Working with Microsoft Visual Studio 2019 v16.3.10 with default installed SQL Server and with Entity Framework Core 3.0.1.

Try to execute: Scaffold-DbContex in PMC console.

Any suggestion is welcome!

jps
  • 20,041
  • 15
  • 75
  • 79
WildHorse
  • 99
  • 1
  • 8

1 Answers1

5

This was working fine for me:

Scaffold-DbContext -connection "Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=DemoDb;Integrated Security=True" -Provider "Microsoft.EntityFrameworkCore.SqlServer"

WildHorse
  • 99
  • 1
  • 8
  • its better to identify the destination for your output by adding the following script with your code -OutputDir Models to be Scaffold-DbContext -connection "Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=DemoDb;Integrated Security=True" -Provider "Microsoft.EntityFrameworkCore.SqlServer" -OutputDir Models – Ahmad Hindash Dec 19 '20 at 00:57
  • 2
    This is working it is weird that in the appsetting the connection string have \\ but if you are running Scaffold-DbContext the connectiong string should only have \. – Ronald Abellano Oct 30 '21 at 10:32
  • 1
    @RonaldAbellano It's because the former is valid JSON which requires backslashes to be escaped via "\\". Within the console these need to be reversed to single ones. – Beltway May 17 '22 at 07:51
  • 1
    All I needed to do as well was change my connection string from \\ to \ – Andrew Jun 07 '22 at 13:28