0

Yes, one more question about Provider manifest token. Unfortunately all previous 22 questions was not useful to solve my problem. I developing simple web application using MVC4 + Code First + Sql Express.

Here is my context descendant:

public class MCQContext : DbContext
{
    public MCQContext()
        : base("name=ApplicationConnection")
    {

    }
    ...............
}

And here - part of web.config related to the problem:

<configuration>
  <configSections>
    <section name="entityFramework"
             type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
             requirePermission="false" />
  </configSections>

  <connectionStrings>
    <add name="ApplicationConnection"
         connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="name=ApplicationConnection" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>

So, as you can see, correct connection string passed to base of context class (I got the same error if I rename connection string to "MCQContext" and do not pass anything to parent context class).

I have no idea how to fix it. This behavior reproduced if I creating absolutely empty MVC4 application, remove all packages (I prefer manually specify required assemblies and do not use NuGet) and fix references (including reference to sqlserver express).

Alex G.P.
  • 9,609
  • 6
  • 46
  • 81
  • Did you catch [this answer](http://stackoverflow.com/a/4117158/861716) in the 22? – Gert Arnold Dec 22 '12 at 20:50
  • Yep. Unfortunately it does not helps. – Alex G.P. Dec 22 '12 at 21:12
  • 1
    What does fail? How does it fail? What's the stack trace and exact exception messate? Are you using EF4 or EF5 (I don't think you can use EF6 with MVC currently) - just wanted to confirm. Also what is the .NET Framework version on your box. Finally are you using VS2010 or VS2012? – Pawel Dec 23 '12 at 03:23
  • Try this if you're still having problems. Create an edmx, letting the IDE generate it. Look at the source to see how that is obtaining connection. See if you can use that in your Code First approach. – Mukus Dec 25 '12 at 07:28

1 Answers1

0

The problem with your connection string here is:

<add name="TrempimModel"
 connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
                   AttachDBFilename=|DataDirectory|aspnetdb.sdf;
                   User Instance=true"
 providerName="System.Data.SqlClient" />

You're basically defining what "server" you're connecting to - but you're not saying what database inside the file to connect to. Also - the file extension for SQL Server Express database files is .mdf (not .sdf - that's SQL Server Compact Edition) - you need to take that into account, too! (was a typo, according to comment by OP).

You need to define an extra database=.... (or Initial Catalog=.....) in your connection string:

 <add name="TrempimModel"
 connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
                   database=YourDatabaseName;
                   AttachDBFilename=|DataDirectory|aspnetdb.mdf;
                   User Instance=true"
 providerName="System.Data.SqlClient" />

Then it should work just fine.

niteshkodle
  • 161
  • 1
  • 6