sql-server - 仅在 Azure Pipelines 上用户“sa”登录失败
问题描述
我正在尝试在我的 azure 管道中运行 e2e 测试。但是服务无法正确启动,因为它们无法连接到 sql 并出现以下错误:
Error: 18456, Severity: 14, State: 7
Login failed for user 'sa'. Reason: An error occurred while evaluating the password. [CLIENT: 172.18.0.9]
令人困惑的部分是,它只在天蓝色管道上失败。在我的本地机器上它可以正常工作。我已经尝试过不同的密码和连接字符串。我在 azure 管道和我的机器上运行一个 linux 容器。
码头工人-compose.yml:
version: '3.4'
services:
sqldata:
image: mcr.microsoft.com/mssql/server:2017-latest
identity-api:
image: ${REGISTRY:-PROJECTNAME}/identity.api:${PLATFORM:-linux}-${TAG:-latest}
build:
context: .
dockerfile: Dockerfile
depends_on:
- sqldata
docker-compose.override.yml
version: '3.4'
services:
sqldata:
environment:
- SA_PASSWORD=Pass@word
- MSSQL_SA_PASSWORD=Pass@word
- ACCEPT_EULA=Y
ports:
- "5433:1433"
identity-api:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:80
- ConnectionString=Server=sqldata;Database=IdentityDb;User Id=sa;Password=Pass@word
解决方案
问题是当服务尝试连接并运行迁移时数据库仍在启动。我添加了一个检查以等待主数据库在服务迁移之前准备好。
while (IsServerConnected(connectionString) == false)
{
logger.LogWarning("Database server not ready ({ConnectionString})...", connectionString);
Thread.Sleep(5000);
}
...
private static bool IsServerConnected(string connectionString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
try
{
connection.Open();
return true;
}
catch (SqlException)
{
return false;
}
}
}
推荐阅读
- javascript - 无法在未安装的组件上调用 setState(或 forceUpdate)
- r - 如何在 R 正则表达式中排除一些模式,有些可能是 2 个或更多字符
- http - 如何在一个请求后停止 HTTP 服务功能
- javascript - Firefox 是否有它可以支持的最大事件源数量?
- java - Spark 不均匀地分配负载
- c# - Java Web 服务向 C# 客户端发送数据的最佳方法
- vb.net - 如何在visual basic中找到5中最大的数字?
- php - 在 XAMPP 中更改 PHP 文件路径
- c - 带有断言的内联函数创建一个未定义的引用?
- sql - 在 SQL 中拥有子类的外键的正确方法?