I have this error when trying to execute request to my Rest API running on Docker:
Microsoft.Data.SqlClient.SqlException (0x80131904): 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: TCP Provider, error: 35 - An internal exception was caught) ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (00000005, 0xFFFDFFFF): Name or service not known
This is my connection string:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "server=sqlserver,1433;Database=Test;Trusted_Connection=False;ConnectRetryCount=0;User Id=sa;Password=Password3784"
}
}
This is my docker-compose.yml:
version: '3.4'
services:
test:
image: ${DOCKER_REGISTRY-}test
build:
context: .
dockerfile: Test/Dockerfile
sqlserverService:
image: microsoft/mssql-server-linux:2017-latest
hostname: 'sqlserver'
environment:
ACCEPT_EULA: Y
SA_PASSWORD: "Password3784"
volumes:
- ./data/mssql:/var/opt/mssql3
ports:
- '1433:1433'
expose:
- 1433
Using SQL Server Management Studio on my computer login with this credentials works fine. localhost,1433 sa Password3784
portsalready exposes ports to containers in the swarm soexposeseems redundant. Does it improve if you only use ports 1433:1433? - AlwaysLearning