Reputation: 4606
I am trying to read the connection string value from the current executing assembly's config settings-
public static string ConnectionString
{
get
{
string path = Assembly.GetExecutingAssembly().Location;
Configuration config = ConfigurationManager.OpenExeConfiguration(path);
return config.ConnectionStrings["DBCon"].ToString();
}
}
I am getting below error which says-
'ConfigurationElement.this[ConfigurationProperty]' is inaccessible due to it's protection level
Any help on this?
Upvotes: 1
Views: 816
Reputation: 1679
Try
return config.ConnectionStrings.ConnectionStrings["DBCon"].ToString();
config.ConnectionStrings
returns a ConnectionStringsSection
object which is public but whose elements [string]
are internal. However ConnectionStringsSection
has a public ConnectionStrings
property which is a ConnectionStringSettingsCollection
object whose elements [string]
are public.
Upvotes: 1