1

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
5
  • 1
    please copy your docker line. in stead of using image. if you need to access your sql server from docker, you need to use IP address of you SQL server, not local host Commented Jan 15, 2021 at 17:01
  • I actually used 127.0.0.1 for connection and im getting the same result Commented Jan 15, 2021 at 17:15
  • not even that ip, I am talking about instance ip in LAN like 192.168.x.x as example. It should be external accessable. Imagine you need to connect 2 computers on lan. you do not use 127.0.0.1 Commented Jan 15, 2021 at 17:22
  • oh, now that i used another ip im getting another error something about Kerberos, at least i think is connectig to the database Commented Jan 15, 2021 at 17:27
  • yes, thanks for the help Commented Jan 16, 2021 at 4:20

1 Answer 1

3

You have simply 2 issues with your connection string:

  1. Your first issue is you need to replace localhost with database (external) ip address. Both localhost and 127.0.0.1 are internal ip address.
  2. When number one is fixed, you get Kerberos issue, you can not use Integrated Security, you need to use database user name and password with the proper rights. Regarding this part check my answer.
Sign up to request clarification or add additional context in comments.

Comments

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.