如何设置数据库连接字符串以从Visual Studio Online进行连续部署 [英] How to set database connection strings in for continuous deployment from visual studio online

本文介绍了如何设置数据库连接字符串以从Visual Studio Online进行连续部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an MVC website that I can publish to azure from visual studio with no problem. In the publish wizard, I specified connection strings for two databases associated with the website.

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

I am trying to set up continuous deployment for this site. When I check in a change a cloud build is initiated and completes successfully. I know as well that the changes are deployed. That said, they are not being deployed with the connection information for the database, and I'm not sure how to set it.

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

I think the database connection is the problem because when I navigate to the site after the deployment I get this error:

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中,然后在构建定义"中将部署路径设置"设置为该配置文件设置文件:

Because the connection information is normally supplied in the Publish wizard, I had an intuition that the solution would be there. I tried checking my Publish profile settings file into VSO and then setting the "Path to Deployment Settings" in the Build Definition to that profile settings file:

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

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

In addition, I added connection strings for the databases to the publish settings file:

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

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

But I get the same error stack trace when I deploy the site.

我将重申,当我使用发布"命令从Visual Studio直接发布到Azure时,该站点将按预期运行.因此,我很确定连接字符串正确.我不确定是否要在发布配置文件中为数据库指定正确的名称,或者不确定部署路径设置"实际上是否以发布配置文件作为输入,或者该输入的格式是否正确,等等.

I will reiterate that when I publish directly to azure from Visual Studio using the "Publish" command, the site works as expected. So I'm pretty sure the connection strings are correct. I'm not sure whether I am giving the correct names to the databases in the publish profile, or if the Path to Deployment Settings actually takes a publish profile as input, or if that input is properly formatted here, etc.

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

How can I correctly configure the deployment to associate the site with the right database for the database context in my application?

谢谢!

推荐答案

经过大量挖掘,我认为我找到了解决方法.

After a lot of digging, I think I found the solution.

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

The connection strings for the site can be configured in Azure using the instructions posted here:

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

基本上是您:

  • 转到网站,选择您的网站
  • 选择配置
  • 在连接字符串"部分中输入所需的连接字符串

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

It was a bit confusing for a bit because I was naming the connection strings ClassNameContext as opposed to ClassName (these are Entity framework code first classes). It works when I use ClassName as the connection string name. If anyone knows how I could look up what the required connection string names here are that would be helpful to know for the future.

这篇关于如何设置数据库连接字符串以从Visual Studio Online进行连续部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆