I am creating a console application and in order to read the connection string , I created a App.Config file and inside app.config file, I created a section called connectionStrings. Below is my connection string in app.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="IdDatabase"
connectionString="Server=testser;Database=testdata; User id=test; Password=test" />
</connectionStrings>
</configuration>
I am reading the connection string like so:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["IdDatabase"].ConnectionString);
}
}
I am getting an error at this line:
optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["IdDatabase"].ConnectionString);
saying ConfigurationErrorsException: Unrecognized configuration section add.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…