使用Docker图像Azure Sql Edge更新Mac上的ASP.NET EF核心数据库

qgelzfjb  于 2023-02-15  发布在  Docker
关注(0)|答案(2)|浏览(128)

我是Mac新手,使用Docker Image运行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数据库更新时,我不断收到以下错误。

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)

如何解决此问题?我是否遗漏了什么?
谢谢你。

3phpmpom

3phpmpom1#

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

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

dgiusagp2#

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

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

相关问题