找不到 Azure In App SQL 数据库的主机

Could not find Host of Azure In App SQL Database

我已经为我的 Azure 应用程序在应用程序数据库中创建了一个 MySQL,并为其获取了连接字符串。此字符串被注入 application.json,然后用于创建实际连接:

WebApplicationBuilder builder = // get it somewhere
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection")
builder.Services.AddDbContext<DatabaseContext>(options => options.UseMySQL(connectionString));

只有...没有连接字符串有效。带有端口 (Database=localdb;Data Source=127.0.0.1:53844;User Id=azure;Password=password) 的抛出:

System.Net.Sockets.SocketException (11001): No such host is known.

没有端口的 (Database=localdb;Data Source=127.0.0.1;User Id=azure;Password=password) 抛出:

System.Net.Sockets.SocketException (10013): An attempt was made to access a socket in a way forbidden by its access permissions.

This question sugested 另一个连接字符串 (Server=127.0.0.1; Port=53844; Database=localdb; Uid=azure; Pwd=password),奇怪的是,即使定义了端口,它也会抛出此异常:

System.Net.Sockets.SocketException (10013): An attempt was made to access a socket in a way forbidden by its access permissions.

并且 the manual 建议另一个字符串 (server=localhost;database=localdb;user=azure;password=password),它再次抛出两个异常之一,具体取决于端口是否存在。

通过浏览器连接正常,所以我可以确认端口、用户名和密码正常工作。

为了确定,我也尝试将“localhost”作为主机。相同的结果。

我做错了什么?

它是所有这些连接字符串的混合体:

server=localhost;port=53844;database=localdb;user=azure;password=password

(端口和服务器分开,但都存在。)

现在适合我。