【问题标题】:MVC SportsStore: systems.ArgumentException unhandled by user code?MVC SportsStore:用户代码未处理的 systems.ArgumentException?
【发布时间】:2011-03-16 14:56:58
【问题描述】:
public class SqlProductsRepository : IProductsRepository
{
   private Table<Product> productsTable;
   public SqlProductsRepository(string connectionString)
   {
       **productsTable = (new DataContext(connectionString)).GetTable<Product>();
   }
   public IQueryable<Product> Products
   {
       get { return productsTable; }
   }
}

这是来自 pro asp.net 书籍的 SportsStore 示例(这里是源代码的github link)。当我运行代码时,它显示 system.ArgumentException 错误。谁能告诉我这个错误到底是什么,我该如何解决? 错误显示在粗体区域。

错误:不支持关键字:元数据"

连接字符串:

SQL 存储库:

公共类 SqlProductsRepository : IProductsRepository { 私有表 productsTable;

  public SqlProductsRepository(string connectionString)
   {
       productsTable = (new DataContext(connectionString)).GetTable<Product>();
   } 

   public IQueryable<Product> Products
   {
       get { return productsTable; }
   }

【问题讨论】:

    标签: asp.net asp.net-mvc-2 argumentexception


    【解决方案1】:

    很可能,connectionString 设置不正确。

    设置后立即解析连接字符串。如果在解析时发现语法错误,则会产生运行时异常,例如 ArgumentException。其他错误只有在尝试打开连接时才能发现。

    更多信息可在此处获得: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx

    【讨论】:

    • 连接字符串对我来说看起来不错。我不知道为什么会出现这个错误
    • 您可以在这里发布您的连接字符串吗?
    • 我发布了我的连接字符串。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-11
    • 1970-01-01
    • 2013-12-28
    • 2014-10-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多