我试图通过在Linux Docker映像上运行来对我的ASP.Net Core 2.2 Web应用程序进行Docker化。但是,当我尝试连接到在本地Windows计算机上运行的SQL Server时,出现以下错误。 我尝试过的一些事情是:
TCP\IP
,将Listen All
设置为yes
,IPAddress => IPAll => TCP Port = 49172 DataSource=DESKTOP-2LS7578\\SQLEXPRESS
使用DataSource=192.168.18.65\\SQLEXPRESS
DataSource=DESKTOP-2LS7578\\SQLEXPRESS
使用DataSource=<IP Address listed under NAT>\\SQLEXPRESS:49172
< / li>
更新2(使用here中的说明):
我还能尝试什么?
StackTrace:
处理请求时发生未处理的异常。
SocketException:成功
Microsoft.Data.SqlClient.SNI.SSRP.GetPortByInstanceName(字符串browserHostName,字符串instanceName)SqlException:建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (提供者:TCP Provider,错误:25-连接字符串无效)
Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity身份,SqlConnectionString connectionOptions,SqlCredential凭据,对象providerInfo,字符串newPassword,SecureString newSecurePassword,布尔重定向用户实例,SqlConnectionString userConnectionOptions,SessionData reconnectSessionData,布尔applyAccessientFaultHandling >
Dockerfile:
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["Scrubber/Scrubber.csproj", "Scrubber/"]
COPY ["SimplerProducts.MicrosoftEntityFrameworkCoreStorage/SimplerProducts.MicrosoftEntityFrameworkCoreStorage.csproj", "SimplerProducts.MicrosoftEntityFrameworkCoreStorage/"]
RUN dotnet restore "Scrubber/Scrubber.csproj"
COPY . .
WORKDIR "/src/Scrubber"
RUN dotnet build "Scrubber.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "Scrubber.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Scrubber.dll"]
答案 0 :(得分:0)
通过在连接字符串中未指定实例名称并使用SQL Server身份验证,我能够使应用程序正常运行。
即将连接字符串从Data Source=DESKTOP-2LS7578\\SQLEXPRESS;Integrated Security=True;
更改为Data Source=host.docker.internal,1433;User ID=<UserID>;Password=<Password>;