Entity framework 如何在中设置数据库连接字符串以从visual studio online进行连续部署

Entity framework 如何在中设置数据库连接字符串以从visual studio online进行连续部署,entity-framework,asp.net-mvc-4,visual-studio-2013,continuous-integration,azure-devops,Entity Framework,Asp.net Mvc 4,Visual Studio 2013,Continuous Integration,Azure Devops,我有一个MVC网站,我可以从VisualStudio毫无问题地发布到azure。在发布向导中,我为与网站关联的两个数据库指定了连接字符串 我正在尝试为此站点设置连续部署。当我签入更改时,将启动云构建并成功完成。我也知道已经部署了更改。也就是说,它们没有部署数据库的连接信息,我不知道如何设置 我认为数据库连接是问题所在,因为在部署后导航到站点时,会出现以下错误: System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exc

我有一个MVC网站,我可以从VisualStudio毫无问题地发布到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>" />
部署设置的路径$//mysite.azurewebsites.net.PublishSettings 此外,我还在发布设置文件中添加了数据库的连接字符串:

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>" />

但在部署站点时,我会得到相同的错误堆栈跟踪

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

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


谢谢大家!

经过大量挖掘,我想我找到了解决办法

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

基本上你:

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

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

我也有同样的问题,但作为WebRole部署到CloudServices,而不是使用网站,因此我不确定在这种情况下如何修复它。奇怪的是,当我部署到我的登台实例时,它工作正常,但仅部署到生产实例时,它无法正确更新连接字符串。我也有同样的问题,通过web.config转换设置连接似乎很奇怪,直接在发布配置文件中,甚至可以选择发布配置文件…然后让azure CD忽略它!