我将我的 API 从免费计划中移出 app service
基本计划app service
与 custom domain
和 SSL certificate
.
1) 我看到我的 API 应用程序的状态是“正在运行”,身份验证 (AAD) 工作正常
2) 如果我打开它的 api 定义(即 */swagger/docs/v1)它正在工作
3) 如果我尝试不尝试访问后端 Azure sql db 的请求,那么它工作正常
4) 如果我使用调用后端 Azure SQL 数据库的请求(它在将 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](Func
1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)\r\n at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass65
1.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__DisplayClass14
1.b__13()\r\n at System.Data.Entity.Internal.LazyEnumerator1.MoveNext()\r\n at System.Collections.Generic.List
1..ctor(IEnumerable1 collection)\r\n at System.Linq.Enumerable.ToList[TSource](IEnumerable
1 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 中的同一个“位置”……到目前为止,在将 API 迁移到自定义域时,我还没有找到有关 Azure SQL 数据库连接的任何建议……
有什么想法吗?
最佳答案
事实证明,出于某种奇怪的原因,在移动到自定义域 - 发布设置后,AzureDatabase
连接字符串不存在(接缝如“生成的”名称 -> 添加了 Api 名称后缀 _db) 数据库名称。当我将它更改为真实的数据库名称时,一切又开始工作了......
附言我想取消选中“在运行时使用此连接字符串(更新目标 web.config)”会得到相同的结果,因为 web.config
拥有正确的连接字符串。
关于azure - 将 Azure API 应用程序移动到自定义域后无法访问 Azure SQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42677120/