views:

54

answers:

3

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

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

But it doesnt 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?
Thanks

+1  A: 

Add a reference to System.Configuration to your project and use ConnectionStrings instead of AppSettings

vc 74
+2  A: 

in .net 4 you have to use

ConfigurationManager.ConnectionStrings("name of connection string in web.config")

more about it is here and here

Nealv
+1 for the links and "to-the-point"ness
tsimbalar
+3  A: 

Use string connectionString = ConfigurationManager.ConnectionStrings[connectionName].ConnectionString;
Make sure to add reference to System.configuration in your project.

sh_kamalh
thanks i forgot to add the reference
CoffeeCode