我正在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" />
如果需要任何其他细节,请询问。提前致谢
答案 0 :(得分:1)
当您创建新的MVC 5应用程序并选择“个人用户帐户”时,会包含一个新的ASP.NET身份提供程序,它使用实体框架6 代码优先。当访问身份时第一次,Entity Framework检查数据库是否存在。除非另有配置,否则它使用“DefaultConnection”来查找标识数据库。如果在调用Identity时数据库不存在,则EF会自动创建数据库。当第一个用户注册时,将创建数据库。