DanJosef
DanJosef

Reputation: 353

How to set database connection strings in for continuous deployment from visual studio online

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!

Upvotes: 4

Views: 1576

Answers (1)

DanJosef
DanJosef

Reputation: 353

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.

Upvotes: 3

Related Questions