2

I'm having an issue with my project. All started with docker, when I try to run it with IIS Express, it works normally, but when I use Docker the database just doesn't connect and return data. I tested it with a local SQL Server 2019 database and it is connecting normal, I don't know if the issues is with docker or maybe the version with the SQL Server.

I'm using SQL Server 2008 SP3.

Connection string in both cases (when it works, IIS, and when it doesn't, docker)

"SQLConnection": "Data Source=server;Initial Catalog=mydatabsae;User ID=user;Password=mypassword;MultipleActiveResultSets=True"

DockerFile

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

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-bionic AS build
WORKDIR /src
COPY ["Buscador.csproj", ""]
RUN dotnet restore "./Buscador.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "Buscador.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Buscador.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Buscador.dll"]

Edit: I'm getting this error:

SqlException: 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=18; handshake=124; [Login] initialization=2; authentication=9; [Post-Login] complete=14466;

6
  • Can you please add additional details: Is the code running in the container when local sql server works? What is the connection string where it works? What is the connection string when the container doesn't work? What are the error messages? What else have you tried to isolate the problem? Commented Jan 25, 2021 at 17:35
  • It works when the code is running outside the container, with IIS. The connection string is actually the same in both cases. The error message that im always getting is basically a timeout error, to be honest im not sure how to isolate it I just tried with a different database with bassically the same string connection and it works Commented Jan 25, 2021 at 17:45
  • Does this answer your question? .Net Core Docker Image cannot access database when running in docker Commented Jan 25, 2021 at 17:54
  • no, that problem is when im not using sql authentication for connecting but im actually using it ( i had that problem before) Commented Jan 25, 2021 at 17:59
  • Could you solve that issue? Commented Jan 28, 2021 at 14:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.