private static void Validate(object value) { if (value == null) { throw new ArgumentNullException("sqlCacheDependency"); } SqlCacheDependencySection section = (SqlCacheDependencySection)value; int pollTime = section.PollTime; if ((pollTime != 0) && (pollTime < 500)) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Invalid_sql_cache_dep_polltime"), section.ElementInformation.Properties["pollTime"].Source, section.ElementInformation.Properties["pollTime"].LineNumber); } }
public static void Main() { // <Snippet1> // Get the Web application configuration. System.Configuration.Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("/aspnetTest"); // Get the section. string configPath = "system.web/cache/sqlCacheDependency"; System.Web.Configuration.SqlCacheDependencySection sqlDs = (System.Web.Configuration.SqlCacheDependencySection)webConfig.GetSection( configPath); // </Snippet1> // <Snippet2> // Get the current Databases collection. SqlCacheDependencyDatabaseCollection databasesValue = sqlDs.Databases; // </Snippet2> // <Snippet3> // Get the current PollTime property value. Int32 pollTimeValue = sqlDs.PollTime; // Set the PollTime property to 500 milliseconds. sqlDs.PollTime = 500; // </Snippet3> // <Snippet4> // Get the current Enabled property value. Boolean enabledValue = sqlDs.Enabled; // Set the Enabled property to false. sqlDs.Enabled = false; // </Snippet4> }
private static void Validate(object value) { if (value == null) { throw new ArgumentNullException("sqlCacheDependency"); } Debug.Assert(value is SqlCacheDependencySection); SqlCacheDependencySection elem = (SqlCacheDependencySection)value; int defaultPollTime = elem.PollTime; if (defaultPollTime != 0 && defaultPollTime < 500) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_sql_cache_dep_polltime), elem.ElementInformation.Properties["pollTime"].Source, elem.ElementInformation.Properties["pollTime"].LineNumber); } }
public static void Main() { // <Snippet1> // Get the Web application configuration. System.Configuration.Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("/aspnetTest"); // Get the section. string configPath = "system.web/cache/sqlCacheDependency"; System.Web.Configuration.SqlCacheDependencySection sqlDs = (System.Web.Configuration.SqlCacheDependencySection)webConfig.GetSection( configPath); // Get the databases element at 0 index. System.Web.Configuration.SqlCacheDependencyDatabase sqlCdd = sqlDs.Databases[0]; // </Snippet1> // <Snippet2> // Get the current PollTime property value. Int32 pollTimeValue = sqlCdd.PollTime; // Set the PollTime property to 1000 milliseconds. sqlCdd.PollTime = 1000; // </Snippet2> // <Snippet3> // Get the current Name property value. string nameValue = sqlCdd.Name; // Set the Name for this configuration element. sqlCdd.Name = "ConfigElementName"; // </Snippet3> // <Snippet4> // Get the current ConnectionStringName property value. string connectionNameValue = sqlCdd.ConnectionStringName; // Set the ConnectionName property. This is the database name. sqlCdd.ConnectionStringName = "DataBaseName"; // </Snippet4> // <Snippet5> SqlCacheDependencyDatabase dbElement0 = new SqlCacheDependencyDatabase( "dataBase", "dataBaseElement", 500); // </Snippet5> // <Snippet6> SqlCacheDependencyDatabase dbElement1 = new SqlCacheDependencyDatabase( "dataBase1", "dataBaseElement1"); // </Snippet6> }