简体   繁体   中英

Cant connect to on premise SQL Server from ASP.NET Core 3.1 in Docker

I have created ASP.NET MVC Core web app in VS 2019 with Docker support , added EF with connection string:

Server=169.x.x.xx;Database=ca-v2-staging;User Id=ca-v2-staging;Password=xxxx

When debugging on IIS Web App has no problem connecting to the database which is hosted remotely but when I run from Docker the web app just hangs. It does not return an exception, it just hangs .

I was tried to add port at the end of IP address 169.xxxx,1433 and execute code below to find out is port opened in Docker and it is. Why EF can't connect to database?

using (var tcpClient = new System.Net.Sockets.TcpClient())
            {
                try
                {
                    tcpClient.Connect("169.x.x.xx", 1433);
                    Console.WriteLine("Port open");
                }
                catch (Exception)
                {
                    Console.WriteLine("Port closed");
                }
            }

I use default Dockerfile which VS 2019 creates and even added EXPOSE 1433 1433 but no luck.

It seems the problem is with SSL and Docker image. Changing to a bionic image solves the problem. More about this https://github.com/dotnet/SqlClient/issues/222

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-bionic AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-bionic AS build

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM