【问题标题】:Default account controller not creating database in MVC 5默认帐户控制器未在 MVC 5 中创建数据库
【发布时间】:2016-11-12 11:56:32
【问题描述】:

我正在 ASP.NET MVC5 中创建一个 Web 应用程序。当我创建项目时,自动添加了一个名为 AccountController 的控制器,其中包含所有必要的功能。现在,当我运行应用程序并注册新用户或尝试登录时,它会出现一些错误。当我运行它时,它应该在 App_data 中创建一个数据库,但它没有创建任何数据库并给出以下错误。谁能帮我解决一下

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]

连接字符串是:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-EmployeeOrderSystem-20160710042802.mdf;Initial Catalog=aspnet-EmployeeOrderSystem-20160710042802;Integrated Security=True" providerName="System.Data.SqlClient" />

如果需要任何其他细节,请询问。提前致谢

【问题讨论】:

    标签: asp.net sql-server asp.net-mvc entity-framework asp.net-mvc-5


    【解决方案1】:

    当您创建一个新的 MVC 5 应用程序并选择“个人用户帐户”时,将包含一个使用 Entity Framework 6 代码优先的新 ASP.NET 身份提供程序。当为第一次,Entity Framework 检查数据库是否存在。除非另有配置,否则它使用“DefaultConnection”来查找身份数据库。如果调用Identity时数据库不存在,EF会自动创建数据库。当第一个用户注册时,创建数据库。

    【讨论】:

    • 我正在做你提到的完全相同的事情,但我得到了我上面提到的错误。
    猜你喜欢
    • 1970-01-01
    • 2013-01-03
    • 2019-10-11
    • 1970-01-01
    • 1970-01-01
    • 2016-07-10
    • 1970-01-01
    • 2016-08-08
    相关资源
    最近更新 更多