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

标签 c# sql-server asp.net-mvc entity-framework asp.net-mvc-3

我在运行应用程序时遇到上述异常。该应用程序正在使用 asp.net mvc 3/C#。我制作了一个 mdf 文件并将其添加到 Visual Web Developer Express 的 App_Data 文件夹下。我将连接字符串添加到 web.config 文件夹,但是当我运行并浏览到/store 时,我收到上面的错误,并突出显示 var categories = storeDB.Categories.ToList(); 行。我的数据库包含 6 个表,其中一个是类别。

Controller :

EventCalendarEntities storeDB = new EventCalendarEntities();

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

web.config 文件中的连接字符串:

<connectionStrings>
   <add name="EventCalendarEntities"
        connectionString="data source=.\SQLEXPRESS;
        Integrated Security=SSPI;
        AttachDBFilename=|DataDirectory|\MvcEventCalendar.mdf;
        User Instance=true"
        providerName="System.Data.SqlClient" />
</connectionStrings>

最佳答案

这通常意味着一个简单的配置问题:

  • 也许真的没有这样的 table
  • 也许表在那里,但没有 dbo 方案(它可能在 Fred.Categories 中)
  • 也许数据库是区分大小写的(这很好),而表实际上是 dbo.CATEGORIES

其中任何一个都会导致上述异常。特别是,您声明:

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

现在到机器类别 != 类别

关于c# - SQLException (0x80131904) : Invalid object name 'dbo.Categories' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5374482/

相关文章:

asp.net-mvc - 访问 IIS Express 上运行的 ASP.NET MVC 中嵌入式 RavenDB 的管理面板

c# - WPF 用另一个替换 UIElement

c# - 标签文本每秒刷新一次

sql-server - 报告服务 (ssrs) 提示输入用户名/密码

asp.net - 将字符串数组作为参数传递给 asp.net mvc webapi 方法

asp.net - web api方法返回json格式的数据?

c# - MySqlParameter 作为表名

c# - 工作单元模式——管理父子关系

sql-server - 不带 Order By 子句的 SQL Select 语句的顺序

sql-server - 如何在SQL Server 表的所有列中选择具有空值的行?