将 Azure API 应用程序移动到自定义域后无法访问 Azure SQL 数据库

Can not access Azure SQL database after moving Azure API app to custom domain

我将我的 API 从免费计划 app service 转移到基本计划 app service,其中包含 custom domainSSL certificate

1) 我看到我的 API 应用程序的状态是 "running",身份验证 (AAD) 工作正常

2) 如果我打开它的 api 定义(即 */swagger/docs/v1)它正在工作

3) 如果我尝试不尝试访问后端 Azure sql 数据库的请求,那么它工作正常

4) 如果我使用调用后端 Azure SQL db 的请求(它在将 API 移动到自定义域之前有效),它会失败并出现此错误:

{"The underlying provider failed on Open., StackTrace: at System.Data.Entity.Core.EntityClient.EntityConnection.Open()\r\n at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions)\r\n at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)\r\n at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass651.b__63()\r\n at System.Data.Entity.Infrastructure.DbExecutionStrategy.Execute[TResult](Func1 operation)\r\n at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQueryReliably[TElement](String commandText, String entitySetName, ExecutionOptions executionOptions, Object[] parameters)\r\n at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQuery[TElement](String commandText, ExecutionOptions executionOptions, Object[] parameters)\r\n at System.Data.Entity.Internal.InternalContext.<>c__DisplayClass141.b__13()\r\n at System.Data.Entity.Internal.LazyEnumerator1.MoveNext()\r\n at System.Collections.Generic.List1..ctor(IEnumerable1 collection)\r\n at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)\r\n
at P..Repositories.DataAccessLayer.DbContexts.P..DbContext.GetP..Dtos()\r\n at P..Repositories.Repositories.P..Repository.P..Repository..ctor()\r\n at P..API.Controllers.A..Controller.Get()"}]}

到目前为止我发现的唯一一件事表明我的 API 由于防火墙规则无法访问 Azure SQL,但这听起来不是一个选项,因为我刚刚分配了一个为我的应用程序自定义域,我相信它在 Azure 中是相同的 "place"... 到目前为止我还没有设法找到有关迁移 API 时 Azure SQL 数据库连接的任何建议到自定义域...

有什么想法吗?

事实证明,出于某种奇怪的原因,在移动到自定义域 - 发布设置后,AzureDatabase 连接字符串不存在(接缝如 "generated" 名称 -> Api 名称加上后缀 _db) 数据库名称。当我将其更改为真实的数据库名称时,一切又开始工作了...

P.S。我想取消选中 "use this connection string at runtime (update destination web.config)" 会得到相同的结果,因为 web.config 持有正确的连接字符串。