How to communicate with SQL Server 2019 container hosted inside Docker from Azure Data Studio

Viewed 728

I am trying to create a login web application in visual studio (.NET core web app). I am using Azure Data Studio(ADS) to connect to the local database for the application. But when I run the application using docker, the web app loaded successfully but it fails to load the local database.

Now, after looking for some solutions online, I pulled an image of the SQL Server 2019 container on Docker and connected it to ADS. I am unable to set up a connection string in visual studio to the SQL Server database hosted inside the docker on ADS.

Can someone provide any leads on how can I set up the connection between my login app and SQL server container inside Docker on ADS?

Error Message in Nugget Package Manager Console

enter image description here

1 Answers

This is one of the ways Connecting to SQL Server container hosted inside Docker.

Assuming that you have executed the below-mentioned command to execute the SQL Server 2019 container.

docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Sample123$" -p 1433:1433 --name mssql2019indocker -d mcr.microsoft.com/mssql/server:latest

Azure Data Studio:

You can use server=localhost, Authentication Type=SQL Login, User name = sa, and password = Sample123$. These details are based on the command you have executed which creating the container. Please refer to the image below.

Azure Data Studio to Login into SQL Server 2019 Docker Container SQL Server 2019 Docker Container

Note: If you are using the EF Core tools to migrate the database the server should be "localhost" as shown in the Azure Data Studio login image.

.NET Core application connecting to Docker Container

Here the situation is .NET core application is executing in one Docker container, and SQL Server 2019 is executing in another container.

Please execute the below-mentioned command to find out the IPAddress of the SQL Server 2019 Docker container. Please refer to the image below. In my scenario, the IPAddress is 172.17.0.3.

docker inspect <ContainerIdOfSQLServer2019>

Once you get IPAddress, please update it in the below-mentioned connection string.

Server=<IPAddressOfTheSqlServer2019DockerContainer>;Database=myDataBase;User Id=myUsername;Password=myPassword;

Finding IP Address of SQL Server 2019 Docker container Finding IP Address of SQL Server 2019 Docker container

Executing the Web App with Docker Configuration Executing the Web App with Docker Configuration

Related