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.

Comments

  • Harry

    The script I downloaded is probably broken. All the table names are singular instead of plural. Took me hours to figure out the error. Anyway, it is working now.