2011-12-13 74 views
2

我是一名初学者,一般使用C#和MVC,我一直在关注MVC Music Store tutorial,因为我的任务问题类似于教程(它是一个商店)。但是,我遇到了一个问题。我需要将SQL Server Express用于数据库而不是SQL Server Compact。MVC 3 - 使用SQL Server Express

我改变了连接字符串,当它编译它不工作..

<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

+0

我们不能看到你改变了连接字符串,请确保您已经安装了SQL Express和连接字符串正确地反映了你的sql express实例所在的位置。你可以在http://www.connectionstrings.com找到连接字符串的更多细节。 –

+0

你是否收到错误?你能否定义“它不工作”是什么意思? –

+0

erm原来它使用 Edwin

回答

1

您的连接字符串错误。

而不是AttachDbFilename=|DataDirectory|FashionStyle.mdfInitial Catalog=[DB-NAME],与您的数据库的名称而不是[DB-NAME]

如需进一步连接字符串参考,你可以看看这个网站:http://www.connectionstrings.com/sql-server-2008

0

的ConnectionString:

Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes; 
+0

欢迎来到StackOverflow:如果您发布代码,XML或数据样本,请**在文本编辑器中突出显示这些行,然后单击“代码样本”按钮(“ }')在编辑器工具栏上进行恰当的格式化和语法突出显示! –

相关问题