Search code examples
c#.net.net-4.0entity-framework-4

Getting the connectionstring in .net 4


I want to get a connection string from the app.config file.

connectionString = System.Configuration.ConfigurationSettings.AppSettings["DBEntities"];

But it doesn't work. It's empty.

I cannot access the System.Configuration.ConfigurationManager because it's .NET 4. How can I get my connection string from the app.config?


Solution

  • Use

    string connectionString = ConfigurationManager.ConnectionStrings[connectionName].ConnectionString; 
    

    Make sure to add reference to System.configuration in your project.