Configuration Using Connection String
In order to stay connected with the data base we need to give the database path in each and every page but this becomes tedious when we want to change the ip address of the path. so, this requires changes performed in every single page.
To resolve this we can put the data base path in the config file so when the modifications needed we just have to change the path in config file not in each and every page.
web.config-
1. Go to config file.
2. Delete the <ConnectionStrings> tag with the data inside.
3. Insert <AppSettings> in place of <ConnectionStrings> .
4. Inside <AppSettings> insert <add> tag.
5. <add> has two atttributes.
i. key- Any key can be assigned[it is user defined]
ii. value- the value attribute is contained the path of database(paste the data base path inside the value attribute)
.aspx.cs[Code window]-
Include System.configuration library.
Connection open code-
string cn = ConfigurationManager.AppSettings["Key_name"];
cn = new SqlConnection();
cn.Open();
Comments
Post a Comment