首页 > 解决方案 > Azure KeyVault Config Builder 连接字符串导致超时

问题描述

目前正在尝试使用配置构建器在我们的 .net 应用程序中填充我们的 web.config 连接字符串,这会导致超时。我按照这个指南。我可以确认数据库的密码是正确的。我也已经尝试过确保通过 Azure CLI 登录。这无济于事。我还要注意我们在数据库中使用 vpn。

错误

SqlException: Connection Timeout Expired.  The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement.  This could be because the pre-login handshake failed or the server was unable to respond back in time.  The duration spent while attempting to connect to this server was - [Pre-Login] initialization=356; handshake=14649; 

System.Data.EntityException: 'The underlying provider failed on Open.'

Web.config 文件:

 <configSections>
    <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
  </configSections>
  <configBuilders>
    <builders>
    <add name="AzureKeyVault" vaultName="{vaultname}" type="Microsoft.Configuration.ConfigurationBuilders.AzureKeyVaultConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Azure, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /></builders>
  </configBuilders>
  <connectionStrings  configBuilders="AzureKeyVault">
  
      <add name="Entities" connectionString="" providerName="System.Data.EntityClient" />
    <add name="ADConnectionString" connectionString="LDAP://52.157.144.83:389/DC=INFORMATIONSECURITYTOOLKIT,DC=Local" />
  </connectionStrings>

有没有更好的方法可以诊断这里发生了什么?

标签: c#.netazureentity-frameworkazure-keyvault

解决方案


我让它工作了。不同之处在于,当我在应用服务部署中编辑要与 @Microsoft.KeyVault 机密引用一起使用的连接字符串时,与仅使用本地 web.config 中的 azure key vault config builder 相比。在前者中,我将 tcp:......, 1433 包含在数据源/服务器名称中,然后将 id=id@server(即 sa@server.windows.net)包含在 id 中。在我的本地 web.config 中,我删除了这些更改,并且成功了。


推荐阅读