开发者

Error Creating Database with EF Code first on Azure

I keep getting a Invalid object name when tring to use entity framework code first against a Azure database. It is a MVC 3 project where I created a Model then the Controllers using EF and a new Context. Here is a list of the steps Ive taken to resolve it. I'm hoping I'm missing something obvious.

  1. Download VS 2010 SP1
  2. Download EF 4.1
  3. set up a firewall exception in Azure for my external IP.
  4. set the Connection string shown in Azure in my Web.config
  5. Turn of开发者_JAVA技巧f my firewall to rule this out.

It seems the index page is trying to pull back results, but the solution is not creating the database as it should so there is no database and I get a error occurred while executing the command defintion. Anyone?


We found that it was important that the SQL Azure database did not already exist. EF code first would fail even if we had an entirely empty database.

Try letting EF create the database entirely from scratch.


There are a few things you could try. To make sure you can create the database, apparently your login needs access to the master database, and PersistSecurityInfo needs to be True in your connection string:

(down at the bottom) http://social.msdn.microsoft.com/Forums/en/adonetefx/thread/1e828c99-66a9-4094-87ec-e799bd619463

Secondly, you need to tell the application to create the database if it doesn't already exist. Inside of your Application_Start method in Globals.asax.cs, try this little snippet:

using System.Data.Entity;
...
...
protected void Application_Start() {
   Database.SetInitializer<Models.FunContext>(new CreateDatabaseIfNotExists<Models.FunContext>());
}

Hopefully this helps, happy coding!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜