在尝试为我的应用程序设置包含sql端口的sql端口时,我收到了以下错误:-
An unhandled exception occurred while processing the request.
SqlException: Cannot open database "xyzDatabase" requested by the login. The login failed.Login failed for user 'sa'.WebMVC: Docker文件配置:-
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /src
COPY ["src/Web/WebUI/WebUI.csproj", "src/Web/WebUI/"]
COPY ["src/Core/Application/Application.csproj", "src/Core/Application/"]
COPY ["src/Infrastructure/Persistence/Persistence.csproj", "src/Infrastructure/Persistence/"]
RUN dotnet restore "src/Web/WebUI/WebUI.csproj"
COPY . .
WORKDIR "/src/src/Web/WebUI"
RUN dotnet build "WebUI.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "WebUI.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebUI.dll"]创业:-
public static IServiceCollection AddSqlServerDatabase(this IServiceCollection services, IConfiguration configure)
{
services.AddEntityFrameworkSqlServer()
.AddDbContext<CatalogContext>(options =>
{
options.UseSqlServer(configure["ConnectionString"],
sqlServerOptionsAction: resilient =>
{
//resilient.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name);
resilient.EnableRetryOnFailure(maxRetryCount: 10, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null);
});
}, ServiceLifetime.Scoped);
services.AddEntityFrameworkSqlServer()
.AddDbContext<AppIdentityDbContext>(options =>
{
options.UseSqlServer(configure["ConnectionString"],
sqlServerOptionsAction: resilient =>
{
resilient.EnableRetryOnFailure(maxRetryCount: 10, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null);
});
}, ServiceLifetime.Scoped);
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<AppIdentityDbContext>()
.AddDefaultTokenProviders();
return services;
}docker-合成文件:-
version: '3.4'
services:
sql.data:
image: microsoft/mssql-server-linux:2017-latest
webui:
image: ${DOCKER_REGISTRY-}webui
build:
context: .
dockerfile: src/Web/WebUI/Dockerfile
depends_on:
- sql.datadocker-compose.override.yml
version: '3.4'
services:
sql.data:
environment:
- SA_PASSWORD=Pass@word
- ACCEPT_EULA=Y
ports:
- "5433:1433"
webui:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:80
- ConnectionString=Server=sql.data;Database=eWebShopDatabase;User=sa;Password=Pass@word
ports:
- "5107:80"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro我知道书的意思是什么,但我真的不明白它想说什么:- 卷:${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro, 当我们从项目中添加"Container支持“时,它会自动添加。
我真的不明白我是需要在将sql图像容器附加到asp.net核心应用程序之前创建一个用户名,还是根据代码中实现的值来默认创建。
appsettings.json文件:-
{
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=xyzDatabase;User=sa;Password=Pass@word;"
}docker构建并创建了容器映像文件,但它没有运行或无法启动数据库,因为它无法登录,可能是用户不存在,也可能无法创建。
有人可能会面临这样的问题,并希望对这个问题有一些见解!
谢谢!
发布于 2019-08-07 10:22:33
SA_PASSWORD与MSSQL_SA_PASSWORD不是一回事。尝试使用这个docker-compose.override.yml代替:
version: '3.4'
services:
sql.data:
environment:
- MSSQL_SA_PASSWORD=Pass@word
- ACCEPT_EULA=Y
ports:
- "5433:1433"
webui:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:80
- ConnectionString=Server=sql.data;Database=eWebShopDatabase;User=sa;Password=Pass@word
ports:
- "5107:80"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro参考文献:在Docker上配置Server容器映像
https://stackoverflow.com/questions/57391779
复制相似问题