3

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 off 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?

1
  • 1
    Have you tried your code with a local database? Change your connection string to a local database and check if the database is created. If it's not being created then you know the fault is in your EF code. Commented Aug 11, 2011 at 9:38

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Yea when I finally figure this out I was like Doh! Thanks
Did you ever figure out WHY it couldn't exists? Due to some limitation in SQL Azure? It's supposed to be a supported scenario, at least outside of Azure, right?
1

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.