Deploying EF Code First DB to AppHarbor. Set your Alias!

This post is really just a reminder to myself, because I always forget this one darn step when deploying an ASP.NET site that uses EF CodeFirst to AppHarbor.

Normally, I would do some local development and use SQL Server Local DB, which by default will make a connection string that looks like this in the App.config file:

    <add name="DashboardEntities"
         connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\DashboardEntities.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />

Before deploying to AppHarbor you will want to set up SQL Server. This means going to AppHarbor, creating your new application, and then adding a SQL Server service to it (I just use the free one).

Now this is the one step I always forget to do…

Before you deploy your code, go to the SQL Server settings page on AppHarbor. Then click the Go To SQL Server link. By default it will have a Connectionstring alias of (unknown). Click on the Edit Alias link, and set the alias to the “name” attribute of your EF connection string. So in my example above, I want my alias to be set to “DashboardEntities”.

Now the app can be deployed to AppHarbor and it will properly replace the EF connection string. Yay!

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

CodingWithSpike is Jeff Valore. A professional software engineer, focused on JavaScript, Web Development, C# and the Microsoft stack. Jeff is currently a Software Engineer at Virtual Hold Technologies.

I am also a Pluralsight author. Check out my courses!

%d bloggers like this: