How to configure SQL Server docker before docker run in vs19


I have pulled the docker for SQL Server and run it using this command.

docker run -e 'ACCEPT_EULA=Y' -e "SA_PASSWORD=12345678Aa" -e "MSSQL_PID=Express" -p 1433:1433 -d

When I try to run my project in Visual Studio via IIS Express,it's running correctly.

enter image description here

But I try to run it using docker it gives me connection error.

enter image description here

My coonection string is : Server=ms-sql-server,1433;Database=aspnet-WebApplication-4167B36A-F12A-4C4C-AEAC-5B6C8ADA1384;Trusted_Connection=False;User Id=SA;Password=12345678Aa

The connection error is : Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot open database "aspnet-WebApplication-4167B36A-F12A-4C4C-AEAC-5B6C8ADA1384" requested by the login. The login failed. Login failed for user 'sa'.

How to configure my SQL Server docker in VS 19 in my project?

asked on Stack Overflow Jun 23, 2020 by Anik Saha • edited Jun 24, 2020 by Anik Saha

1 Answer


The app and mssql service are likely to be on different networks when you use it in a docker container, considering that you have not defined it.

A quick way to resolve this is to change the name of your service in the connection string by its IP number, in the appsettings, as follows:

"ConnectionString":"Server=,1433;Database=aspnet-WebApplication-4167B36A-F12A-4C4C-AEAC-5B6C8ADA1384;Trusted_Connection=False;User Id=SA;Password=12345678Aa"

User contributions licensed under CC BY-SA 3.0