当我尝试从Visual Studio 15连接到localdb时,遇到了问题。我已经安装了SQL Server Express 2016。
我按照以下教程操作:http://www.asp.net/mvc/overview/getting-started/introduction/creating-a-connection-string
我创建了模型和上下文(MovieDBContext)类并尝试设置连接:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MvcMovie-20130603030321.mdf;Initial Catalog=aspnet-MvcMovie-20130603030321;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="MovieDBContext" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True" providerName="System.Data.SqlClient"
/>
当我尝试访问显示所有电影的页面时:
public ActionResult Index()
{
return View(db.Movies.ToList());
}
我得到了这个异常:
![在此输入图片描述](https://istack.dev59.com/DJ5vh.webp)
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-MvcMovie-20130603030321.mdf;Initial Catalog=aspnet-MvcMovie-20130603030321;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="MovieDBContext" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True" providerName="System.Data.SqlClient"
/> </connectionStrings>
当我使用(local)MSSQLLocalDB
时,会出现这个异常。
我做错了什么?