簡體   English   中英

無法通過 docker 連接到 SQL 服務器數據庫

[英]Can't connect to SQL Server database via docker

我在嘗試僅使用 docker 連接到我的 MSSQL 數據庫時遇到問題,我已經嘗試使用 IIS Express 及其正確顯示數據,但是當我嘗試從請求中獲取數據時出現此錯誤。

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)

我驗證了 TCP/IP 是否啟用以及 1433 端口。我也在使用這個字符串連接

"TestConnection": "Server=localhost,1433;Database=BDREPOSITORIO;Integrated Security=True"

而我的dockerfile就是這個

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

您的連接字符串只有 2 個問題:

  1. 您的第一個問題是您需要將 localhost 替換為數據庫(外部)ip 地址。 localhost 和 127.0.0.1 都是內部 ip 地址。
  2. 當第一是固定的,你得到 Kerberos 問題,你不能使用集成安全,你需要使用具有適當權限的數據庫用戶名和密碼。 關於這部分檢查我的答案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM