Mssql-docker: Impossible to connect to the mssql-server-windows-express from asp.net core application.

Created on 4 Apr 2019  路  2Comments  路  Source: microsoft/mssql-docker

I could download and run the microsoft/mssql-server-windows-expressSo this is works:

docker run -d -p 1433:1433 -e sa_password=MyPassword1 -e ACCEPT_EULA=Y microsoft/mssql-server-windows-express
I can connect it via the powershell and via the Sql server management studio (localhost, 1433 and SA and MyPass1) So I can see the databases and play with them.

However in .NET core API application I cannot connect to the dockerized mssql server express (windows dockerized and not linux)

  "ConnectionStrings": {
    "Default": "Server=127.0.0.1,1433;Database=master;User=sa;Password=MyPassword1 ;"
  },

Unfortunately I get this sql exception always:

System.Data.SqlClient.SqlException: '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: 0 - No connection could be made because the target machine actively refused it.)'

So the mssql-server-windows-express container is running I can reach it by the powershell command and by the sql server management studio, but when I run the .net core api applicaion in the visual studio 2017 I get this sql exception always.

mssql-server-windows

Most helpful comment

Maybe its too late but I'll give an answer.

I had the same issue. The problem is that you're using 127.0.0.1 in your _connectionString_ instead of the host machin IP address as @forkazmoden said. That solved my problem.

Don't forget you're inside a container so 127.0.0.1 refer to your AspNetCore container but NOT to the host machin. That's why you can login sucessfully from Powershell or SSMS to your MSSQL Server because in this case 127.0.0.1 address refer to your host machin.

All 2 comments

Hi,

"ConnectionStrings": {
    "Default": "Server=127.0.0.1,1433;Database=master;User=sa;Password=MyPassword1 ;"
  },

Could you try to change the IP address to the host where you run the container? You can use ipconfig command to find it. Please refer to Connect from outside the container.

Maybe its too late but I'll give an answer.

I had the same issue. The problem is that you're using 127.0.0.1 in your _connectionString_ instead of the host machin IP address as @forkazmoden said. That solved my problem.

Don't forget you're inside a container so 127.0.0.1 refer to your AspNetCore container but NOT to the host machin. That's why you can login sucessfully from Powershell or SSMS to your MSSQL Server because in this case 127.0.0.1 address refer to your host machin.

Was this page helpful?
0 / 5 - 0 ratings