在Mac上使用Docker映像的Azure Sql Edge更新ASP.NET EF Core数据库

3

我是Mac的新手,使用Docker镜像成功运行了Azure Sql Edge。 这是我运行该镜像的命令。

docker run -d --name SQLServerImg -e ACCEPT_EULA=Y -e SA_PASSWORD=StrongPassword@123 -p 1433:1433 mcr.microsoft.com/azure-sql-edge

这是我appsettings.json中的连接字符串。
"ConnectionStrings": {
    "EmployeesManagementDB" : "Server=127.0.0.1,1433;Database=EmployeesManagementDB;MultipleActiveResultSets=true;User Id=sa;Password=StrongPassword@123"
  }

这是我的Progoram.cs文件

builder.Services.AddControllers();
var connectionString = builder.Configuration.GetConnectionString("EmployeesManagementDB");
builder.Services.AddDbContext<EmployeeContext>(options => options.UseSqlServer(connectionString));

当我运行 dotnet ef database update 命令时,一直出现以下错误。
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)

我该如何解决这个问题?我有什么遗漏的吗?
谢谢。
2个回答

0

在您的连接字符串中,参数"User Id"似乎是错误的, 请尝试将其替换为"User"。 此外,请尝试从连接字符串中删除"MultipleActiveResultSets=true"。

尝试:

"ConnectionStrings": {
"EmployeesManagementDB" : "Server=127.0.0.1,1433;Database=EmployeesManagementDB;User=sa;Password=StrongPassword@123"}

0

你可能缺少信任服务器证书的标志。只需添加 "TrustServerCertificate=True;":

"ConnectionStrings": {
    "EmployeesManagementDB" : "Server=127.0.0.1,1433;Database=EmployeesManagementDB;User=sa;Password=StrongPassword@123;TrustServerCertificate=True;"
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接