Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
331 views
in Technique[技术] by (71.8m points)

c# - SqlException (0x80131904): Invalid object name 'dbo.Categories'

I am getting the exception above when I run an application. The application is using asp.net mvc 3 / C#. I made an mdf file and added it under App_Data folder in Visual Web Developer Express. I added connection strings to the web.config folder but when I run and browse to /store, I get the error above with the line var categories = storeDB.Categories.ToList(); highlighted. My database contains 6 tables and one of them is Category.

Controller:

EventCalendarEntities storeDB = new EventCalendarEntities();

public ActionResult Index()  
{  
    var categories = storeDB.Category.ToList();  
    return View(categories);  
}    

Connection strings in web.config file:

<connectionStrings>
   <add name="EventCalendarEntities"
        connectionString="data source=.SQLEXPRESS;
        Integrated Security=SSPI;
        AttachDBFilename=|DataDirectory|MvcEventCalendar.mdf;
        User Instance=true"
        providerName="System.Data.SqlClient" />
</connectionStrings>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This usually means a simple configuration issue:

  • perhaps there genuinely is no such table
  • perhaps the table is there, but there is no dbo scheme (it might be in Fred.Categories)
  • perhaps the db is case-sensitive (which is fine), and the table is actually dbo.CATEGORIES

Any of these will cause the above exception. In particular, you state:

My database contains 6 tables and one of them is Category.

Now to a machine, Category != Categories


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...