I need to have a custom connection string in the web.config because I need to ping to Database only during day time say between 8AM and 5 PM, because of this I thought of creating custom configuration.
so I tried creating a class which extends from the class ConfigurationSection, Please find the coding which I have done.
Expand|Select|Wrap|Line Numbers
- class ExtendedConnection:ConfigurationSection
- {
- // Start time of Connection
- [ConfigurationProperty("startTime", IsRequired = true)]
- public string StartTime
- {
- get { return (string)this["startTime"]; }
- set { this["startTime"] = value; }
- }
- // End time of Connection
- [ConfigurationProperty("endTime", IsRequired = true)]
- public string EndTime
- {
- get { return (string)this["endTime"]; }
- set { this["endTime"] = value; }
- }
- // Connction Name
- [ConfigurationProperty("connectionName", IsRequired = true)]
- public string ConnectionName
- {
- get { return (string)this["connectionName"]; }
- set { this["connectionName"] = value; }
- }
- // Connection String
- [ConfigurationProperty("connectionString", IsRequired = true)]
- public string ConnectionString
- {
- get { return (string)this["connectionString"]; }
- set { this["connectionString"] = value; }
- }
- public ExtendedConnection()
- { }
- }
Expand|Select|Wrap|Line Numbers
- <configuration>
- <configSections>
- <section name="TestExtended" type="ExtendedConnection"/>
- </configSections>
- <system.web>
- <compilation debug="true" targetFramework="4.0" />
- <TestExtended startTime="08:00" endTime="16:00" connectionName="constring" connectionString="server=SQLEXPRESS;Initial Catalog=master;Trusted_Connection=Yes;Integrated Security=SSPI"></TestExtended>
- </system.web>
- </configuration>
where am I doing the mistake, please help. I am using VS2010 express edition