locked
EF 4.3 Error Question RRS feed

  • Question

  • When running my app I get an error message; I get the error on public SchedulingContext()
                : base("SchedulingContext") statement:

    The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.

    My code (snippets):

    App.config

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <connectionStrings>
        <add name="SchedulingContext" connectionString="Data Source=XXX\SQL2008R2DEV;Initial Catalog=YYY;Persist Security Info=True;User ID=sa;Password=XXX"
             providerName="System.Data.SqlClient"/>
      </connectionStrings>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </configSections>
    </configuration>

    SchedulingContext.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.Entity;

    namespace SchedulingApp
    {
        public class SchedulingContext : DbContext
        {
            public DbSet<Zone> Zones { get; set; }
            public DbSet<Schedule> Schedules { get; set; }

            public SchedulingContext()
                : base("SchedulingContext")
            {

            }
        }
    }

    Tuesday, February 28, 2012 5:54 PM

Answers

  • Hi GuyD,

    Welcome!

    Please put ConnectionStrings after <ConfigSections> in App.config file:

    <?xml version="1.0" encoding="utf-8"?>
     <configuration>
          <configSections>
         <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
         <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
       </configSections>
    <connectionStrings>
         <add name="SchedulingContext" connectionString="Data Source=XXX\SQL2008R2DEV;Initial Catalog=YYY;Persist Security Info=True;User ID=sa;Password=XXX"
              providerName="System.Data.SqlClient"/>
       </connectionStrings>
     </configuration>
    Have a nice day.

    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Guy Dillen Friday, March 2, 2012 11:48 AM
    Wednesday, February 29, 2012 7:23 AM

All replies

  • Hi GuyD,

    Welcome!

    Please put ConnectionStrings after <ConfigSections> in App.config file:

    <?xml version="1.0" encoding="utf-8"?>
     <configuration>
          <configSections>
         <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
         <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
       </configSections>
    <connectionStrings>
         <add name="SchedulingContext" connectionString="Data Source=XXX\SQL2008R2DEV;Initial Catalog=YYY;Persist Security Info=True;User ID=sa;Password=XXX"
              providerName="System.Data.SqlClient"/>
       </connectionStrings>
     </configuration>
    Have a nice day.

    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Guy Dillen Friday, March 2, 2012 11:48 AM
    Wednesday, February 29, 2012 7:23 AM
  • Hi,

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions?
    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 2, 2012 9:05 AM
  • Hi,

    Thanks this solved the problem.

    Guy

    Friday, March 2, 2012 11:48 AM