Reputation: 961
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
Upvotes: 3
Views: 2506
Reputation: 2208
Your connection string is wrong.
Instead of AttachDbFilename=|DataDirectory|FashionStyle.mdf
write Initial 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
Upvotes: 2
Reputation: 74
ConnectionString:
Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;
Upvotes: 0