I am developing an ASP.NET Web API on VS Code (macOS) and trying to connect it to my SQL Server running in Docker. However, I keep getting the following error:
Cannot connect to SQL Server Browser. Ensure SQL Server Browser has been started.
Environment:
Connection string (appsettings.json):
"ConnectionStrings": {
"DefaultConnection": "Server=localhost,1433;Database=YourDB;User Id=sa;Password=****;TrustServerCertificate=True;"
}
What I've tried:
lsof -i -P -n | grep LISTEN | grep 1433
, and it shows that SQL Server is listening on port 1433.sqlcmd -S localhost,1433 -U sa -P Str0ngP@ssword!
, but I get:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
I forgot about how I run the scaffold command on my backend, it had the instance name included on it (mentioned by @AlwaysLearning). I just had to run the scaffold command again with the correct values to fix it, which is this:
dotnet ef dbcontext scaffold "Server=localhost,1433;Database=CanteenDB;User Id=sa;Password=******;TrustServerCertificate=True;" Microsoft.EntityFrameworkCore.SqlServer -o Entities --force