ASP.Net 2.0 provides a new feature to define the connection string in web.config file for the database connection with ASP.Net Web applications. ConnectionStrings section of web.config file is new in ASP.Net 2.0 that enables you to declare the connection string globally in a safe separate file. You can access the connection string declares in the web.config file anywhere in your ASP.Net web application project. You can declare as many connection strings in the web.config file as you need. For example if you have number of database sources of different type such as SQL Server database, Access Database ore MySQL database, you can declare different connection strings in the ConnectionStrings sub section of Configuration Section of the web.config file.
<configuration>
</connectionStrings>
</system.web>
</configuration>
In the above syntax you can see that connection string is added using <add></add> element in the connectionstrings section. <add> element supports 3 attributes:
name: This attribute is used to define the name for the database connection string.
connectionString: This attribute is used to declare the connection string for the database connection according to the connection provider for ASP.Net 2.0 database connectivity drivers and database source type. Each type of database supports different types of connectivity drivers and connection string formats.
providerName: providerName attribute is optional parameter. It is used to pass the provider name class of ASP.Net that will provide the connectivity and Data Access Functions and layers.
Be the first to rate this post
Tags: asp.net 2.0, ado.net, asp.net connectionstring, asp.net web.config, asp.net database connection, asp.net sql connection string, asp.net access connection string, web.config connectionstrings, web.config configuration, odbc microsoft access drivers, oledb connection string
8/27/2008 8:55:37 AM
When same thing can be done using AppSettings ie, declaring Connection strings and using them in App Settings, why did they come up with new section in the webconfig file.
raj
10/11/2008 3:28:46 AM