Dcoker: System.Data.SqlClient.SqlException (0x80131904) in .net core app

0

I have .net core app that connects to mssql with such connection string:

Server=(local);Database=Test;User ID=sa;Password=123;max pool size=1000

My compose file looks like this:

    sql-server-db:
        image: microsoft/mssql-server-linux
        container_name: sql-server-db
        environment:
            - SA_PASSWORD=123
            - ACCEPT_EULA=Y
            - MSSQL_PID=Developer
        ports:
            - "1439:1433"

my-service:
        container_name: my-service
        image: my-service:1.0
        environment:               
            - ASPNETCORE_ENVIRONMENT=Development
            - ASPNETCORE_URLS=http://+:80
        depends_on:
            - sql-server-db    
        ports:
            - "5001:80"

But when the app starts I receive such an error:

System.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: 40 - Could not open a connection to SQL Server)

I can connect to the SQL server by 127.0.0.1,1439 address via sql management studio with these credentials. So I believe this error occurs because my app can not connect to SQL server due to the server name (local). I tried to specify sql-server-db name in my connection string and it works, but I would like to use (local). Is there any way to make it works?

docker
docker-compose
asked on Stack Overflow Nov 26, 2020 by Sheinar

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0