Search code examples
c#asp.netasp.net-mvcconnection-stringconfigurationmanager

Unable to get ConnectionString value from Configuration


I do not know why am I getting this error I have tried everything but I am still getting this error again and again. Any help which would solve this problem will be appreciated.

Here is the error:

enter image description here

Connection string in web.config:

enter image description here


Solution

  • As the extension to the solution which I mentioned in the question's comment:

    EXPLANATION

    According to the article Tale of two web.config in MVC,

    web.config in View folder

    Implemented for blocking access to view folder and files directly via user request or through URL.

    Web.config in project folder

    Where all the appSettings, connectionStrings, configSections and etc. are configured here and these settings/values are able to be accessible for the entire project.


    SOLUTION

    Thus, you need to move the <ConnectionStrings> section from web.config (in the root of the View folder) to Web.config (in the root of the project folder).