2

I am trying to pick up ASP.Net - and following the mvc tutorial: http://www.asp.net/mvc/tutorials/mvc-music-store-part-4 (Note: I am totally new to the .Net framework, both C# and ASP.Net)

At the beginning the tutorial suggested to use SQL Server Compact 4.0 - But, I got the SQL Server Express installed instead (since I will be using it after, not just for the tutorial)

SELECT @@VERSION AS [Version]

Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (Intel X86) Apr 2 2010 15:53:02 Copyright (c) Microsoft Corporation Express Edition with Advanced Services on Windows NT 6.1 <X64> (Build 7600: ) (WOW64)

Now, I am having trouble when I got to the point to set up the db connection for the tutorial. The tutorial step to add this to the Web.config:

<connectionStrings>
    <add name="MusicStoreEntities"
         connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf"
         providerName="System.Data.SqlServerCe.4.0"/>
</connectionStrings>  

But that doesn't work - and pretty sure it's because the different SQL Server that I am using. Suggestion on how to make this work?

I've tried changing the providerName to "System.Data.SqlClient" and it still doesnt work, and I've tried the following too:

  <connectionStrings>
    <add
       name="MusicStoreEntities"
       connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|MvcMusicStore.sdf"
       providerName="System.Data.SqlClient" />
  </connectionStrings>

And it still doesnt work with the following exception: The provider did not return a ProviderManifestToken string

Help with setting up this ASP.Net - SQL Server Express 2008 would be greatly appreciated!


EDIT

Seems like now I got it working, at least to connect to the db:

Now, obviously the database is empty - the tutorial didnt even say about instantiating the database, other than downloading some asset file for the db "SampeData.cs", and add it to the Global.asax.cs Application_Start method:

System.Data.Entity.Database.SetInitializer(new MvcMusicStore.Models.SampleData());

And now, 2 things:

  1. The line above in Application_Start dont seem to be hit when in debug mode (I did try rebuild solution)

  2. Now I am getting the following error: Model compatibility cannot be checked because the database does not contain model metadata. Ensure that IncludeMetadataConvention has been added to the DbModelBuilder conventions.

I think I am missing instantiating the data in the db - but not sure how / what - the tutorial doesnt say much

3 Answers 3

2

I assume that you have restored a copy of the database to SqlExpress. Once you do that, you should add a Database element to the string with the name of the database you restored it as. A helpful resource for connectionstrings is http://www.connectionstrings.com

  <connectionStrings>
    <add
       name="MusicStoreEntities"
       connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;Database=MusicStoreEntities"
       providerName="System.Data.SqlClient" />
  </connectionStrings>

Note that what you have is a link to an .sdf file, which is a SqlCE database. The |DataDirectory| portion is replaced with the location of your App_Data folder in your application.

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

8 Comments

Followed the config that you set, and I still get the same "The provider did not return a ProviderManifestToken string" - what does that error mean anyway?
I'm not sure what that error is. Seems to be related to Entity Framework maybe. You might try 'Integrated Security=True' instead of SSPI.
Edited my original post - seems like now I am connected to the db
@tsOverflow - Ok, looks like Entity Framework creates an SSDL file, and in there you will find a configuration for Schema with a ProviderManifestToken. This is probably configured to use SQL CE, so you will need to change it. Something like this <Schema Namespace="OtimizeModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008"> should work.
I dont see any SSDL file - is it created somewhere?
|
1

This is what I use:

<add name="<CONNECTION NAME>" 
     connectionString="Data Source=<SERVER NAME>;Initial Catalog=<DATABASE>;Persist Security Info=True;User ID=<USER ID>;Password=<PASSWORD>;" 
     providerName="System.Data.SqlClient" />

Replace <...> values with your corresponding values.

Comments

0

I can never remember connection strings, I use this site to figure out what they need to be.

Comments

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.