.NET Software Components
Home Products Services Downloads Support News Articles
Lanteria Solutions - SharePoint Design & Development
 
Home | Artciles | Web Application Settings -.NET Components
Storing of web application settings
Storing settings in database
The following method is based on storing application settings in database.
This method is most flexible and independent from .NET infrastructure, however it requires additional system resources for the performing of database operations.

Review the following example:
SQL Script

/*==============================================================*/
/* Table: Settings */
/*==============================================================*/

create table t_settings (
id int not null,
description nvarchar(255) not null,
value nvarchar(255) not null
)
on PRIMARY
go

insert into t_settings values(1, "Site administrator name", "admin")
insert into t_settings values(2, "Site administrator password", "adminPWD")
insert into t_settings values(3, "Images directory", "img")



Configurator.cs

public enum Settings
{
AdminName = 1,
AdminPassword = 2,
ImagesDir = 3
}

public string GetConfigurationValue(Settings setting)
{
SqlConnection myCnn;
SqlCommand myCmd;
SqlDataReader myReader;

String sSQL = "select * from t_settings where id=" + setting;
myCnn = new SqlConnection(sSQLConnectionString);
myCmd = new SqlCommand(sSQL, myCnn);
myCnn.Open();
myReader = myCmd.ExecuteReader();
myReader.Read();
sSQL = myReader["value"];
myCnn.Close();
return sSQL;
}



SomePage.asax.cs

private void Page_Load(object sender, System.EventArgs e)
{
Configuration conf = new Configuration();
sImagePath = conf.GetConfigurationValue(Settings.ImagesDir);
// :
// Do something
// :
}

An of course let's consider the advantages and disadvantages of using database as a storage for web application parameters.

Advantages:

  1. Centralized storage of all application settings
  2. Settings can be operatively changed
  3. No need in recompilation of whole application
  4. Application restart doesn't occur after the changing of settings

Disadvantages:

  1. Database engine is required
  2. Additional system resources for database operations
  3. General reliability of application decreases
  4. Anyone, who has an access to database, can change application settings
<<Previous ^Context Next>>
 
Aug-10-2007
New SharePoint Partners
Components 4U agreed about the strategic partnership in the area of MS SharePoint products and development.
Feb-26-2007
PAD Parser released
PAD Parser is a new component, designed for working with PAD compatible content

SharePoint Development and Design
SharePoint Directory
About Us Privacy Policy Links Contact Us Copyright © 2004-2007 Components 4U
All Rights Reserved