4

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

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.

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?

Thank you!

2
  • I have the same problem but deploying to CloudServices as a WebRole, not using a web-site, so I'm not sure how to fix it in that case. Weirdly though when I deploy to my staging instance it works fine, it's only deploying to the production instance that it fails to update the connection string properly. Commented Mar 26, 2015 at 21:10
  • I have the same problem, it seems odd to be able to set connections via the web.config transforms, in the publish profile direct and even have the option to select the publish profile...then have it ignored by azure CD! Commented Jun 5, 2015 at 7:25

1 Answer 1

3

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

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/

Basically you:

  • Got to websites, choose your site
  • Choose configure
  • Enter the required connection strings in the Connection Strings section

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.