3

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

6
  • We cannot see what you changed the connection string to, please ensure that you have installed sql express and that the connection string correctly reflects where your sql express instance lives. you can find more detail of connection strings at connectionstrings.com Commented Dec 13, 2011 at 7:17
  • Are you getting an error? Could you please define what it does not work mean? Commented Dec 13, 2011 at 7:18
  • erm originally it used <add name="FashionStyle" connectionString="Data Source=|DataDirectory|FashionStyle.sdf" providerName="System.Data.SqlServerCe.4.0"/> Commented Dec 13, 2011 at 7:20
  • It does not show error, According to the demo it should be importing data from the SampleData.cs into the database, but once I changed it to SQL express the data does not show up and the store page is empty Commented Dec 13, 2011 at 7:22
  • @William Edwin Sieh Have you downloaded the System.Data.SqlServerCe.4.0 blogs.msdn.com/b/sqlservercompact/archive/2011/01/12/… Commented Dec 13, 2011 at 7:27

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

ConnectionString:

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

1 Comment

Welcome to StackOverflow: if you post code, XML or data samples, please highlight those lines in the text editor and click on the "code samples" button ( { } ) on the editor toolbar to nicely format and syntax highlight it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.