2011-12-13 72 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或數據樣本,請**在文本編輯器中突出顯示這些行,然後單擊「代碼樣本」按鈕(「 }')在編輯器工具欄上進行恰當的格式化和語法突出顯示! –

相關問題