I am sorry. I am quite new here. I am trying to practice the beerhouse starter kit so for that reason I am trying to create only Articles module. However the custom configuration class is quite complex and
I cannot fix this configuration error I am getting. I understand the flow as I read your previous posts but I am not able to work around with the connectionstring through the custom configuration class
I have created the following connection by use a gridview control just cheated a bit.
<section name="test" type= "DALCM.Testone, __code" />
....
....
<test defaultConnectionStringName="LocalServer">
<articles pageSize="10"/>
</test>
<connectionStrings>
<remove name="LocalServer"/>
<add name="LocalServer" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\LGateContentMgt.mdf";Integrated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
so in my configuration section I am using
[ConfigurationProperty("defaultConnectionStringName", DefaultValue = "LocalServer")]
public string DefaultConnectionStringName
{
get { return (string)base["defaultConnectionStringName"]; }
set { base["connectionStdefaultConnectionStringNameringName"] = value; }
}
public class ArticlesElement : ConfigurationElement
{
[ConfigurationProperty("connectionStringName")]
public string ConnectionStringName
{
get { return (string)base["connectionStringName"]; }
set { base["connectionStringName"] = value; }
}
public string ConnectionString
{
get
{
string connStringName = (string.IsNullOrEmpty(this.ConnectionStringName) ?
Globals.settings.DefaultConnectionStringName : this.ConnectionStringName); // I am getting error on this line since it is returning null value
return WebConfigurationManager.ConnectionStrings[connStringName].ConnectionString;
}
}
I do not understand why it is returning null value here.
I am using teh following Providertype
[ConfigurationProperty("providerType", DefaultValue = "SqlArticlesProvider.System.Data.SqlClient")]
public string ProviderType
{
get { return (string)base["providerType"]; }
set { base["providerType"] = value; }
}
Please guide me so atleast I should be able to see the connectionstring in my label control that I have created.