【问题标题】:How to set database connection strings in for continuous deployment from visual studio online如何从 Visual Studio Online 中设置数据库连接字符串以进行持续部署
【发布时间】:2015-01-29 08:59:02
【问题描述】:

我有一个 MVC 网站,可以毫无问题地从 Visual Studio 发布到 azure。在发布向导中,我为与网站关联的两个数据库指定了连接字符串。

我正在尝试为此站点设置持续部署。当我签入更改时,会启动并成功完成云构建。我也知道更改已部署。也就是说,它们没有与数据库的连接信息一起部署,我不知道如何设置它。

我认为数据库连接是问题,因为当我在部署后导航到该站点时出现此错误:

System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5341687
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +546
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +5353471
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +145    
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +923
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +311

因为连接信息通常是在发布向导中提供的,所以我有一种直觉认为解决方案就在那里。我尝试将我的发布配置文件设置文件检查到 VSO 中,然后将构建定义中的“部署设置路径”设置为该配置文件设置文件:

Path to Deployment settings  $/<projectpath>/mysite.azurewebsites.net.PublishSettings

此外,我在发布设置文件中添加了数据库的连接字符串:

  <add name="CollateralContext" connectionString="<connection string from azure>" />
  <add name="UsersContext" connectionString="<connection string from azure>" />

但是当我部署站点时,我得到了相同的错误堆栈跟踪。

我将重申,当我使用“发布”命令从 Visual Studio 直接发布到 azure 时,该站点按预期工作。所以我很确定连接字符串是正确的。我不确定我是否在发布配置文件中为数据库提供了正确的名称,或者“部署设置路径”是否实际上将发布配置文件作为输入,或者该输入是否在此处正确格式化,等等。

如何正确配置部署以将站点与应用程序中数据库上下文的正确数据库相关联?

谢谢!

【问题讨论】:

  • 我有同样的问题,但是作为 WebRole 部署到 CloudServices,而不是使用网站,所以我不知道在这种情况下如何解决它。奇怪的是,虽然当我部署到暂存实例时它工作正常,但它只是部署到无法正确更新连接字符串的生产实例。
  • 我有同样的问题,能够通过 web.config 转换设置连接似乎很奇怪,直接在发布配置文件中,甚至可以选择发布配置文件......然后有它被 azure CD 忽略了!

标签: entity-framework asp.net-mvc-4 visual-studio-2013 continuous-integration azure-devops


【解决方案1】:

经过大量挖掘,我想我找到了解决方案。

可以使用此处发布的说明在 Azure 中配置站点的连接字符串:

http://azure.microsoft.com/en-us/documentation/articles/web-sites-configure/

基本上你:

  • 访问网站,选择您的网站
  • 选择配置
  • 在“连接字符串”部分输入所需的连接字符串

这有点令人困惑,因为我将连接字符串命名为 ClassNameContext 而不是 ClassName(这些是实体框架代码的第一类)。当我使用 ClassName 作为连接字符串名称时,它可以工作。如果有人知道我如何在此处查找所需的连接字符串名称,这将有助于将来了解。

【讨论】:

    猜你喜欢
    • 2014-05-20
    • 1970-01-01
    • 1970-01-01
    • 2017-08-28
    • 2019-08-07
    • 1970-01-01
    • 2016-02-23
    • 2016-09-29
    • 1970-01-01
    相关资源
    最近更新 更多