I am making a crud operation in console app using ef. I get an exception
ConfigurationErrorsException: Configuration system failed to initialize
Only one
<configSections>
element allowed per config file and if present must be the first child of the root<configuration>
element...
But there is only one configuration string in app.config
... I have cleaned and rebuilt the solution, and also restarted Visual Studio and checked the versions of EF which is 6, and my project's target version is 4.7.2.
Here is the chunk of the code containing connection string from app.config
and piece of code of DbContext
... please help sorting this out
<connectionStrings>
<add name="StudentsDbContext"
connectionString="Data Source=localhost;Initial Catalog=students;Integrated Security=True;"
providerName="System.Data.SqlClient" />
</connectionStrings>
DbContext
:
public class StudentsDbContext : DbContext
{
public DbSet<Student> Students { get; set; }
}
Program
:
class Program
{
static void Main()
{
StudentsDbContext context = new StudentsDbContext();
while (true)
// .....
}
}
<connectionStrings> </ connectionStrings>
this configuration section should be placed under the location of the <Configsections>
node. Do not seize the first position of the configSections configuration section.
Like this:
If this does not work for you, please let me know