Tuesday, January 31, 2012

application related settings in config file

Title: How to set connection string settings in app.config in c#.net

Here i will describe what are the settings are available in config files and what is the use of those settings .
In asp.net by default no values of current page or accessible to other pages .if we want to define application wide static settings then we can use app settings tag of web.config.This should be written under configuration tag.With above app settings when we run the application automatically id and month are loaded to retrieve the in code they have to use a .net assembly or name space called System.Configuration.

Configuration Manager(old configuration settings) or classes are that are retrieve value from configuration file.All applications that are related to data sources need connection string.It is very difficult to maintain connection string in programs and also to maintain consistent connection strings(connection pooling,asynchronous precessing etc)In .net version this is tag is added to write connection string in configuration level and refuse it for entire project .As per location are data source of project is relocated to connection strings.This connection string written under configuration directly

string str=ConfigurationManager.ConnectionStrings["Con"].ToString();
SqlConnectioncn=new SqlConnection(str);
label.test="database connected";
Data source controls also recommended to save connection string in configuration file.We can use connection string and some other web.config settinggs in markup also.
< % $config settings % >
ex:-connectionString="< % $connectionString:pubs % >"

No comments: