Reputation: 64
I'm having an issue trying to connect to my MSSQL database only with docker, I've already tried with IIS Express and its showing data correctly but when I try to get data from a request I get this error.
SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server)
I verified that TCP/IP is enable and also the 1433 port.Also im using this string connection
"TestConnection": "Server=localhost,1433;Database=BDREPOSITORIO;Integrated Security=True"
And my dockerfile is this
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 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"]
RUN sed -i 's/DEFAULT@SECLEVEL=2/DEFAULT@SECLEVEL=1/g' /etc/ssl/openssl.cnf
RUN sed -i 's/DEFAULT@SECLEVEL=2/DEFAULT@SECLEVEL=1/g' /usr/lib/ssl/openssl.cnf
Upvotes: 1
Views: 489
Reputation: 33377
You have simply 2 issues with your connection string:
Upvotes: 3