Invalid object name ‘dbo.xxx’ using MVC3 and SQL Server
When working through the Movies tutorial on the ASP.NET website, I decided that it’d be fun to try to switch the data provider from SQL Compact to the full version of SQL Server 2008. In preparation for the move, I created a new (blank) database and gave the appropriate permissions to my test account. However, after altering my connection string to accommodate SQL Server 2008, I received the following message:
Invalid object name ‘dbo.Movies’.
At first, I thought that my connection string was off, but it turns out that for Entity Framework to automagically create database tables and relationships, the database must not already exist. As such, simply deleting the blank database completely fixed the problem. This, of course, means that your SQL Server user must have db create privileges, which is something that I don’t grant my test account. To get around this, use more powerful credentials for the initial connection that creates the database. Afterwards, you can switch to a more restricted login.
–Adam
Hi Adam,
I’m not ashamed to say this was an amazing tip. Thank you very much!
Having followed the OdeToFood MVC3 tutorials. I too was sure that it was my connection string and from years of experience with .NET that I would need a blank database because I had a connection string pointing to one.
I spent a couple of hours scratching my head before stumbling upon your post.
Once again thank you for the insight. I can now happily progress with the rest of the tutorials!
Regards,
Jamie
Yay, thanks, this fixed my problem. Hopefully they fix the problem soon since creating a db is an usual step in app development…
Thanks Adam! Onward we go
Thanks for this tip. I was able to get around this issue in about 3 minutes with this post.
Thanks Adam. You saved me after many hours of labor!!!!!!!