MVC 3 - 使用 SQL Server Express
我是一般使用 C# 和 MVC 的初学者,我一直在关注 MVC 音乐商店教程,因为我的作业问题与教程类似(这是一家商店)。但是,我遇到了问题。我需要使用 SQL Server Express 作为数据库而不是 SQL Server Compact。
我更改了连接字符串,当它编译时它不起作用。
<add name="FashionStyle" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|FashionStyle.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
在我的 StoreController
中:
public ActionResult Index()
{
var types = storeDB.Types.ToList();
return View(types);
}
视图:
<h3>Browse Type of Product</h3>
<p>
Select from @Model.Count() type:</p>
<ul>
@foreach (var type in Model)
{
<li>@Html.ActionLink(type.Name, "Browse", new { type = type.Name })</li>
}
</ul>
此外,当我运行并导航到商店页面时,“浏览产品类型从 0 类型中选择: ”出现。我还使用了教程中修改后的 sampledata.cs
I am a beginner to using C# and MVC in general and I have been following the MVC Music Store tutorial because my assignment question is similar to the tutorial (it's a store). However, I am experiencing a problem. I need to use SQL Server Express for the database instead of SQL Server Compact.
I changed the connection string and when it compiles it does not work..
<add name="FashionStyle" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|FashionStyle.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
In my StoreController
:
public ActionResult Index()
{
var types = storeDB.Types.ToList();
return View(types);
}
View:
<h3>Browse Type of Product</h3>
<p>
Select from @Model.Count() type:</p>
<ul>
@foreach (var type in Model)
{
<li>@Html.ActionLink(type.Name, "Browse", new { type = type.Name })</li>
}
</ul>
Also, when I run and navigate to the store page, "Browse Type of Product Select from 0 type:" shows up. I also used a modified sampledata.cs
from the tutorial
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的连接字符串错误。
将
AttachDbFilename=|DataDirectory|FashionStyle.mdf
写入Initial Catalog=[DB-NAME]
,并使用数据库名称代替[DB-NAME]
代码>.有关更多连接字符串参考,您可以查看此站点: http://www.connectionstrings.com/ sql-server-2008
Your connection string is wrong.
Instead of
AttachDbFilename=|DataDirectory|FashionStyle.mdf
writeInitial Catalog=[DB-NAME]
, with your database's name instead of[DB-NAME]
.For further connection string reference, you can check out this site: http://www.connectionstrings.com/sql-server-2008
连接字符串:
ConnectionString: