Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 3 - Using SQL Server Express

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

like image 559
Edwin Avatar asked Nov 27 '25 15:11

Edwin


1 Answers

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

like image 127
Svarog Avatar answered Nov 29 '25 05:11

Svarog



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!