Friday 12 October 2012

What is web.config file in Asp.Net?


Hi friends , Here I have explained what is web.config file in Asp.Net.

Introduction:

Web.config is the central part of the  Asp.Net application. It is used to store the information to be accessed by web page. This  information  could be connectionString stored at at Centralized part so that it can be accessed in data driven page. If the connection string change its  just a matter of changing it at one place.
In the sample  we shall red the information from web.config using Asp.Net .
Below  the code have given as:-
Web.config:
<?xml version=”1.0” encoding=”utf-8”?>
<configuration>
<connectionString>
<add key=”connectionName”  connectionString=”Data Source=DataServerName; Initial Caalog= yourDatabaseName; Integrated Security=True”
</connectionString>
</configuration>
In Asp.Net
String  connStr=ConfigurtionManager.ConnectionString[“connectionName”].ConnectionString;
Sqlconnection  conSql=new SqlConnection(connStr);
consql.Open();
………write your code
conSql.Close();

No comments:

Post a Comment

Note: only a member of this blog may post a comment.