SqlException (0x80131904): 无效的对象名称 'dbo.Categories' [英] SqlException (0x80131904): Invalid object name 'dbo.Categories'
问题描述
我在运行应用程序时遇到上述异常.该应用程序使用 asp.net mvc 3/C#.我制作了一个 mdf 文件并将其添加到 Visual Web Developer Express 的 App_Data 文件夹下.我向 web.config 文件夹添加了连接字符串,但是当我运行并浏览到/store 时,我收到了上面的错误,其中突出显示了 var Categories = storeDB.Categories.ToList();
行.我的数据库包含 6 个表,其中之一是类别.
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.
控制器:
EventCalendarEntities storeDB = new EventCalendarEntities();
public ActionResult Index()
{
var categories = storeDB.Category.ToList();
return View(categories);
}
web.config 文件中的连接字符串:
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>
推荐答案
这通常意味着一个简单的配置问题:
This usually means a simple configuration issue:
- 也许真的没有这样的表
- 也许表格在那里,但没有
dbo
方案(它可能在Fred.Categories
中) - 也许数据库是区分大小写的(这很好),而表实际上是
dbo.CATEGORIES
- perhaps there genuinely is no such table
- perhaps the table is there, but there is no
dbo
scheme (it might be inFred.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:
我的数据库包含 6 个表,其中一个是 Category.
My database contains 6 tables and one of them is Category.
现在到机器,Category
!= Categories
这篇关于SqlException (0x80131904): 无效的对象名称 'dbo.Categories'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!