How To Create a SQL Server Database in AppHarbor

In the last part of the tutorial about how to deploy ASP.NET MVC applications to AppHarbor we pushed an ASP.NET MVC site to AppHarbor.

Although the build was successful an error occured when viewing the site becuase it couldn’t connect to the attached database.

To fix this we need to create a SQL Server Database in Appharbor.

On the AppHarbor application management page click the link to ‘Add database’

App Harbor Build

Next choose SQL Server as the database type, enter a connection string name and click the create button.

I used the same connection string name used by Entity Framework 4 in the ASP.NET MVC Music Store application.

New AppHarbor Database



The following screen shows you what connection string should be used in your config file and information about how to connect to the Appharbor database from Microsoft SQL Server Managemnt Studio.

Database Connection Settings



When you connect to the database in Microsoft SQL Server Managemnt Studio you’ll see the database is empty.

Empty AppHarbor Database



In the Assets/Data folder in the ASP.NET MVC Music Store you’ll find a ‘MvcMusicStore-Create.sql’ SQL script which can be used to create and populate the tables required by the application.

Before running the script delete the first line that looks like this

USE [C:\USERS\JON\DOCUMENTS\JON-SHARE\MVCMUSICSTORE-MVC3\MVCMUSICSTORE\MVCMUSICSTORE\APP_DATA\MVCMUSICSTORE.MDF]

When the script has been completed successfully the tables will have been created and populated

Populated AppHarbor Database



In the next step of this tutorial we will see how to configure ASP.NET MVC to use a SQL Server database in AppHarbor.

How to configure ASP.NET MVC to use a SQL Server database in AppHarbor

In this tutorial about how to deploy ASP.NET MVC applications to AppHarbor is to update the ASP.NET MVC web.config file, commit the change and push the Git repository to AppHarbor.

Modify the connection string in the ASP.NET MVC web.config to use the AppHarbor database created in last tutorial.

<connectionStrings>
  <add name="MusicStoreEntities" 
        connectionString="Server=db003.appharbor.net;Database=db1814;User ID=db1814;Password=<yourpassword>"
        providerName="System.Data.SqlClient" />
</connectionStrings>

In the directory containing your ASP.NET MVC solution, right click and start Git Bash, or start Git Bash and navigate to the directory.

Git Directory Location To Push



Execute the following commands to commit the updated web.config file in the git repository and push to AppHarbor

git add MvcMusicStore/web.config
git commit –m "Now using AppHarbor SQL Server"
git push appharbor master

Once the appliation has been built you should have a working ASP.NET MVC Music store running in AppHarbor.

Working Music Store In AppHarbor

Why I’m using AppHarbor to host my ASP.NET MVC sites

About two months ago I heard about Heroku, a hosting service which can host Ruby apps in the cloud for free.

Heroku

I was envious that Ruby folk could do away with traditional hosting solutions and move to a cloud platform that was fresh, modern and simple to use.

Without paying a penny you get one dyno which handles concurrent HTTP requests which you can easily scale up by adding additional web or background processors without breaking the bank.

Used in conjunction with Jekyll, a static web site generator, one dyno should be adequate for most people’s needs.

So I started putting together a site for my new company.

This was great except I needed to do some custom tasks which meant creating Ruby extensions… which meant I had to learn Ruby.

Then a colleague mentioned AppHarbor.

App Harbor

AppHarbor is like Heroku for .Net developers, providing a free platform to host .Net applications in the cloud.

Similar to Heroku you can scale up but with the added bonus of a free 20mb instance of Sql Server.

I haven’t been so excited by something like this in the .Net world for a while, and am so impressed by what the team have achieved.

There’s plenty of good documentation on how to get started on the web already, so check out

for more information.

Still not impressed?

What if I said that you could push code up to AppHarbor and see changes on your live site within minutes or that AppHarbor only deploys changes to your live site if the build and unit tests are successful?

It’s clever stuff, you’ve effectively got a free continuous integration server in the cloud!

You can even go back and deploy old versions if you ever need to.

AppHarbor is still new so they are missing a couple of useful features at the moment. But they are getting better all the time.

Questions in the support forum and answered quickly, and they really do seem to be listening to the community.

I’ve already moved my company ASP.NET MVC site over and will be writing more about AppHarbor next week.

Page 2 of 212