【问题标题】:Can not access Azure SQL database after moving Azure API app to custom domain将 Azure API 应用程序移动到自定义域后无法访问 Azure SQL 数据库
【发布时间】:2017-03-08 16:47:33
【问题描述】:

我将我的 API 从免费计划 app service 移动到基本计划 app service 以及 custom domainSSL certificate

1) 我看到我的 API 应用的状态是“正在运行”,身份验证 (AAD) 工作正常

2) 如果我打开它的 api 定义(即 */swagger/docs/v1),它就可以工作

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

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

{"底层提供者在打开时失败。, StackTrace: at System.Data.Entity.Core.EntityClient.EntityConnection.Open()\r\n 在 System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(布尔 shouldMonitorTransactions)\r\n 在 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 在 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 在 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 源)\r\n
在 P..Repositories.DataAccessLayer.DbContexts.P..DbContext.GetP..Dtos()\r\n 在 P..Repositories.Repositories.P..Repository.P..Repository..ctor()\r\n 在 P..API.Controllers.A..Controller.Get()"}]}

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

有什么想法吗?

【问题讨论】:

    标签: azure ssl dns azure-sql-database azure-api-apps


    【解决方案1】:

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

    附:我猜取消选中“在运行时使用此连接字符串(更新目标 web.config)”会得到相同的结果,因为 web.config 拥有正确的连接字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多