Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

docker-compose.yml version: "3.9" services: web: build: . ports: - "8000:80" container_name: web_application depends_on: - medicalmgr

medicalmgr:
    image: "mcr.microsoft.com/mssql/server:2019-latest"
    environment:
        SA_PASSWORD: Pw@mm2021
        ACCEPT_EULA: Y
    ports:
        - "1433:1433"
    container_name: mmm_mmsql_2019

dockerfile

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env WORKDIR /app COPY . . RUN dotnet restore &&
dotnet publish -c Release -o out

Build runtime image

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 WORKDIR /app COPY --from=build-env /app/out . ENTRYPOINT ["dotnet", "MedicalManager.dll"]

Startup.cs 's public void CofigureServices(..){ .... var server = Configuration["DBServer"] ?? "medicalmgr"; var port = Configuration["DBPort"] ?? "1433"; var user = Configuration["DBUser"] ?? "SA"; var password = Configuration["DBPassword"] ?? "Pw@mm2021"; var database = Configuration["Database"] ?? "MedicalManager";

   //var connectionStr = $"Server={server},{port};Initial Catalog={database};User ID= 
   //{user};Password={password}";
   var connectionStr = 
   @"Server=medicalmgr;Database=MedicalManager;User=sa;Password=Pw@mm2021;";
   services.AddDbContext<MedicalManagerDBContext>(
            options => options.UseSqlServer(connectionStr)
   );}

Error: Application startup exception: Microsoft.Data.SqlClient.SqlException (0x80131904): 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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.9k views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...