MVC3 Docking on AppHarbor and Entity Framework Code FirstPosted: April 17, 2011
So, I spent last few hours figuring this out. AppHarbor is pretty nice. AppHarbor is free for one application, one database and it does work with SQL Server CE. I just deployed a stripped down version of one of my MVC projects there and it’s pretty smooth. So, here’s a run down of how it’s done, so that someone else might not need hours.
Stripping the project down was a breeze, you’ve got to love Object Oriented design, it’s beautiful. Deploying the project was a no-brainer too, if you’ve had some experience with Git. But testing, as ever brought out the issues.
I was using Entity Framework Code First (EFCF) as my ORM and it likes to drop databases. I didn’t realize it since it’s natural for EFCF to. And for good reason too, for when you change your models. On AppHarbor, you don’t get permissions to create databases. Thus the problem.
But no fear, NuGet to the rescue. Again. Actually, community to the rescue. There’s a workaround for EFCF’s
DontDropDbJustCreateTables. You can find here on NuGet. It plugs in beautifully to your application and all you need to do is enter your context name. Also, you will have to get a new database from AppHarbor since already EFCF dropped it.
Also the connection string should include a
providerName otherwise, exceptions!
<connectionStrings> <add name="connection string name" connectionString="Server=db003.appharbor.net;Database=dbXXXX;User ID=dbXXXX;Password=YourPassword;" providerName="System.Data.SqlClient" /> </connectionStrings>