Not able to connect tp SQL Server database from ASP.NET Core app inside a Docker container

11/5/2019

I have created an ASP.NET Core app which will use SQL Server as its backend which is installed on the local machine. I am using Visual Studio to develop the ASP.NET Core web app and able to connect to SQL Server without any issues if I am running the application through Visual Studio.

After deploying the app inside the Docker container, application is not able to communicate with the SQL Server which is installed on the host machine.

I have enabled "TCP" connection and enabled the port in "Advanced Firewall Settings" on my local machine. I am able to connect to SQL Server with the IpAddress along with PORT (IpAddress, PORT)

Below is the command which I am using it to deploy the image inside the Docker container:

docker run -d -p 5061:80 --name mycurrentserviceapicontainer mycurrentserviceapi --network="host"

Information:

I am able to access the API which is not having DB Connection, but API which has functionality related to DB connection causing an issue.

Issue:

Connection Timeout Expired. The timeout period elapsed during the post-login phase. The connection could have timed out while waiting for server to complete the login process and respond; Or it could have timed out while attempting to create multiple active connections. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=5; handshake=435; [Login] initialization=0; authentication=0; [Post-Login] complete=14251;

Connection String:

Server=ipaddress,49172;Database=DockerDb;User=sa;Password=password;MultipleActiveResultSets=true

49172 - It is the TCP Port and enabled this Port in the Inbound Rule of Windows Firewall and able to connect it through Sql Server Management Studio.

I am not sure why i am getting this issue. I have searched many articles, nothing helped me to rectify this issue. Does any one come across this issue? Please provide your suggestion on this.

Thanks for your time.

-- rajswastik
docker
docker-container
kubernetes

0 Answers