How to fix “The ConnectionString property has not been initialized”

后端 未结 6 469
一生所求
一生所求 2020-11-27 04:58

When I start my application I get: The ConnectionString property has not been initialized.

Web.config:



        
6条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 05:35

    I stumbled in the same problem while working on a web api Asp Net Core project. I followed the suggestion to change the reference in my code to:

    ConfigurationManager.ConnectionStrings["NameOfTheConnectionString"].ConnectionString
    

    but adding the reference to System.Configuration.dll caused the error "Reference not valid or not supported".

    To fix the problem I had to download the package System.Configuration.ConfigurationManager using NuGet (Tools -> Nuget Package-> Manage Nuget packages for the solution)

提交回复
热议问题