vendredi 14 août 2015

Settings in web.config for initialize database

I have Error :HTTP Error 500.19 - Internal Server Error The requested page cannot be accessed because the related configuration data for the page is invalid.

Detailed Error Information:
Module     IIS Web Core
Notification       Unknown
Handler    Not yet determined
Error Code     0x80070032
Config Error       The configuration section 'entityFramework' cannot be read because it is missing a section declaration
Config File    \\?\C:\Project\web.config

I use Entity Fremework Code First. And i'm initialize data for my table:

 namespace Project.NewFolder1.Initializer
{
    public class StackOverFlowInitializer : DropCreateDatabaseAlways<Test123Db>
    {
        protected override void Seed(Test123Db context)
        {
            var category = new List<Category>
            {
                new Category() {NameCategory = "C#"},
                new Category() {NameCategory = "ASP.NET"},
                new Category() {NameCategory = "ASP.NET MVC"},
                new Category() {NameCategory = "HTML"},
            };
            category.ForEach(s => context.Category.Add(s));
            context.SaveChanges();
        }
    }
}

In web.config i set:

 <connectionStrings>  
    <add name="Test123Db" connectionString="data source=.\SQLEXPRESS;initial catalog=StacjOverFlow;integrated security=True;application name=EntityFramework" providerName="System.Data.SqlClient" />
  </connectionStrings>

<entityFramework>
   <contexts>
    <context type="Project.NewFolder1.Test123Db, Project">
      <databaseInitializer type="Project.NewFolder1.Initializer.StackOverFlowInitializer, Project" />
    </context>
</contexts>

</entityFramework>

What may be the problem?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire