Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
474 views
in Technique[技术] by (71.8m points)

c# - ConfigurationErrorsException: Unrecognized configuration section add

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...